package cc.rengu.igas.momp.core.service.trans;

import cc.rengu.igas.momp.common.constant.CommonConstant;
import cc.rengu.igas.momp.common.dao.*;
import cc.rengu.igas.momp.common.dao.impl.*;
import cc.rengu.igas.momp.common.entity.*;
import cc.rengu.igas.momp.common.enums.*;
import cc.rengu.igas.momp.common.util.CommonMessageCheck;
import cc.rengu.igas.momp.common.util.JsonOperation;
import cc.rengu.igas.momp.common.util.MompAmountUtil;
import cc.rengu.igas.momp.common.util.MompDateUtil;
import cc.rengu.igas.momp.facade.bean.*;
import cc.rengu.igas.momp.facade.request.EditMchntFeeDiscountMcDetailRequest;
import cc.rengu.igas.momp.facade.response.EditMchntFeeDiscountMcDetailResponse;
import cc.rengu.oltp.service.base.RadpService;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.service.common.constant.TreeNodeConstant;
import cc.rengu.oltp.service.common.enums.ChannelEnum;
import cc.rengu.oltp.service.common.enums.OltpRpcdEnum;
import cc.rengu.oltp.service.model.BizException;
import cc.rengu.oltp.service.model.BizResponse;
import cc.rengu.oltp.utility.bean.PageInfo;
import cc.rengu.oltp.utility.bean.PageResult;
import cc.rengu.oltp.utility.util.*;
import cc.rengu.utility.base.StringUtil;
import cc.rengu.utility.dbs.Database;
import com.alibaba.fastjson.JSONObject;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 手续费减免类活动信息编辑功能实现
 *
 * @author Jinan Liu
 * @since 2020/4/1 10:58
 */
public class EditMchntFeeDiscountMcDetailInfoService extends RadpService {

    private String globalInstId;
    private String globalMcNo;
    private String globalTimeStamp;
    private String globalOprId;
    private String globalTxnDate;
    private final static String TABLE_NAME = TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode();
    private String globalOrgId;
    private String globalStockMchntType;
    private String globalMchntFlag;
    private BigDecimal zero = BigDecimal.ZERO;
    private boolean merFileFlag = false;
    private String globalFlowNo;
    private String flowAuditStatus = "";
    private String flowTmpAuditStatus = "";
    private String traceNo;
    private boolean auditStatusChangeFlag = false;

    @Override
    protected int bizInit(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizProcess(String s, int i) {

        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        try {

            EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest = new EditMchntFeeDiscountMcDetailRequest();
            ConvertUtil.convertOutput(editMchntFeeDiscountMcDetailRequest);

            EditMchntFeeDiscountMcDetailResponse editMchntFeeDiscountMcDetailResponse = new EditMchntFeeDiscountMcDetailResponse();
            editMchntFeeDiscountMcDetailResponse.setHeader(editMchntFeeDiscountMcDetailRequest.getHeader());
            BizResponse<EditMchntFeeDiscountMcDetailResponse> bizResponse = new BizResponse<>();
            bizResponse.setResult(editMchntFeeDiscountMcDetailResponse);

            globalInstId = editMchntFeeDiscountMcDetailRequest.getHeader().getInstId();
            globalTimeStamp = new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date());
            globalOprId = editMchntFeeDiscountMcDetailRequest.getQueryId();
            globalTxnDate = editMchntFeeDiscountMcDetailRequest.getHeader().getTransDate();
            globalOrgId = editMchntFeeDiscountMcDetailRequest.getQueryOrgId();
            globalStockMchntType = editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getStockMchntType();
            if (null == editMchntFeeDiscountMcDetailRequest.getMchntInfoList() || editMchntFeeDiscountMcDetailRequest.getMchntInfoList().isEmpty()) {
                globalMchntFlag = CommonConstant.ZERO_COMMON_CONSTANT;
            } else {
                globalMchntFlag = CommonConstant.ONE_COMMON_CONSTANT;
            }

            String queryType = editMchntFeeDiscountMcDetailRequest.getQueryType();
            String queryRole = editMchntFeeDiscountMcDetailRequest.getQueryRole();
            String oprType = editMchntFeeDiscountMcDetailRequest.getOprType();

            rglog.debug("QUERY_TYPE=<{}>", queryType);
            rglog.debug("QUERY_ID=<{}>", globalOprId);
            rglog.debug("QUERY_ROLE=<{}>", queryRole);
            rglog.debug("OPR_TYPE=<{}>", oprType);

            /* 报文检查 */
            CommonMessageCheck.checkBizMessageHeader(queryType, globalOprId, queryRole, rglog);
            CommonMessageCheck.checkSingleValue(oprType, rglog);

            if (!StringUtil.isNullorEmpty(editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getMcNo())) {
                globalMcNo = editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getMcNo();
            }
            if (!StringUtil.isNullorEmpty(editMchntFeeDiscountMcDetailRequest.getMrctFilePath())) {
                merFileFlag = true;
                rglog.info("减免类营销活动编辑，商户文件路径：" + editMchntFeeDiscountMcDetailRequest.getMrctFilePath());
            }
            //检查上送的营销活动规则是否相同
            //checkRuleInfo(editMchntFeeDiscountMcDetailRequest);
            //判断上送的商户信息和机构信息是否匹配，即参加活动的商户所属的机构有权限参加活动
            checkMchntAndOrgInfo(editMchntFeeDiscountMcDetailRequest);
            if (editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getStockMchntFlag().equals(CommonConstant.STOCK_MCHNT_FLAG_ONE)) {
                //判断未上送商户号商圈号时，机构下的非特殊费率商户达标统计表是否存该交易日期内的数据
                checkMchntNoAndAreaNo(xmlTreeUtil, editMchntFeeDiscountMcDetailRequest);
            }
            // 服务调用
            BizResponse<EditMchntFeeDiscountMcDetailResponse> bizResponseNew = editMchntFeeDiscountMcDetailInfo(
                    editMchntFeeDiscountMcDetailRequest, editMchntFeeDiscountMcDetailResponse, xmlTreeUtil);

            ConvertUtil.convertInput(bizResponseNew.getResult());

        } catch (BizException e) {
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, e.getCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, e.getMessage());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        } catch (Exception e) {
            rglog.error(StringUtil.ExceptionToString(e));
            try {
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_CODE, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespCode());
                xmlTreeUtil.setXmlTreeStringValue(TreeNodeConstant.RESP_DESC, OltpRpcdEnum.OLTP_PROCESS_ERROR.getRespDesc());
                xmlTreeUtil.setXmlTreeStringValue(CommonConstant.KEY_RESPDESC, e.getMessage());
            } catch (Exception e1) {
                rglog.error(StringUtil.ExceptionToString(e1));
            }
        }

        return CommonConstant.PROCESS_SUCCESS;
    }

    @Override
    protected int bizTerminate(String s) {
        return CommonConstant.PROCESS_SUCCESS;
    }

    /**
     * 商户手续费优惠类营销活动编辑方法
     *
     * @param editMchntFeeDiscountMcDetailRequest  商户手续费优惠类营销活动信息编辑接口请求对象
     * @param editMchntFeeDiscountMcDetailResponse 商户手续费优惠类营销活动信息编辑接口应答对象
     * @param xmlTreeUtil                          内部XML树
     * @return cc.rengu.oltp.service.model.BizResponse<cc.rengu.igas.momp.facade.response.EditMchntFeeDiscountMcDetailResponse> 商户手续费优惠类营销活动信息编辑接口应答对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private BizResponse<EditMchntFeeDiscountMcDetailResponse> editMchntFeeDiscountMcDetailInfo(EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest, EditMchntFeeDiscountMcDetailResponse editMchntFeeDiscountMcDetailResponse, XmlTreeUtil xmlTreeUtil) throws Exception {

        BizResponse<EditMchntFeeDiscountMcDetailResponse> bizResponse = new BizResponse<>();

        /* 判断查询类型 */
        String queryType = editMchntFeeDiscountMcDetailRequest.getQueryType();
        String queryRole = editMchntFeeDiscountMcDetailRequest.getQueryRole();
        String oprType = editMchntFeeDiscountMcDetailRequest.getOprType();
        globalMcNo = editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getMcNo();


        /* 判断用户的角色和权限 */
        if (QueryTypeEnum.BANK_QUERY_TYPE.getQueryTypeCode().equals(queryType)) {

            if (QueryRoleEnum.BANK_BASIC_QUERY_ROLE.getQueryRoleCode().equals(queryRole)) {
                /* 银行人员录入岗-正式表和临时表所有数据 */
                rglog.info("银行人员录入岗开始操作");
                if (OprTypeEnum.EDIT_SAVE.getOprTypeCode().equals(oprType)) {

                    rglog.info("保存数据流程开始");

                    /* 保存数据是完全新增数据的流程，需要生成营销活动编号 */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据； */
                        globalMcNo = generateNewMcNo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());
                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("MC_NO=<{}>", globalMcNo);
                        }

                        /* 开启数据库事务 */
                        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
                        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
                        if (null != corporation && !corporation.isEmpty()) {
                            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
                        }
                        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
                        dbsUtil.dbsBeginTransaction();

                        /* 全部新增流程，插入数据 */
                        insertAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);

                        /* 正常结束数据库事务 */
                        dbsUtil.dbsEndTransaction(true);

                    } else {
                        /* 如果营销活动编号存在，需要根据当前数据库各状态判断是否可以更新数据 */
                        saveAllMcInfoByBank(xmlTreeUtil, editMchntFeeDiscountMcDetailRequest);
                    }

                    rglog.info("保存数据流程结束");

                } else if (OprTypeEnum.EDIT_SUBMIT.getOprTypeCode().equals(oprType)) {

                    rglog.info("提交审批流程开始");
                    /* 提交审批 */
                    submitMcInfo(editMchntFeeDiscountMcDetailRequest);

                    rglog.info("提交审批流程结束");

                } else if (OprTypeEnum.EDIT_DRAFT.getOprTypeCode().equals(oprType)) {

                    rglog.info("修改草稿流程开始");
                    /* 开启数据库事务 */
                    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
                    String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
                    if (null != corporation && !corporation.isEmpty()) {
                        String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
                        dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
                    }
                    DbsUtil dbsUtil = new DbsUtil(dbPoolName);
                    dbsUtil.dbsBeginTransaction();

                    /* 修改草稿 */
                    updateAllDraftMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);
                    /* 正常结束数据库事务 */
                    dbsUtil.dbsEndTransaction(true);

                    rglog.info("修改草稿流程结束");

                } else {
                    rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                    throw new BizException(RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespCode(), RespCodeEnum.NOT_SUPPORTED_OPR_TYPE_ERROR.getRespDesc());
                }

            } else {
                /* 银行审批岗或银行发布岗 */
                rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
                throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
            }


        } else {
            /* 商户、代理商、收银员或用户 */
            rglog.error("当前<{}>角色的查询用户<{}>无权限查看数据!", queryRole, queryType);
            throw new BizException(RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespCode(), RespCodeEnum.NO_AUTHORIZATION_TO_QUERY_ERROR.getRespDesc());
        }

        bizResponse.setRspSysId(ChannelEnum.MOMP.getChannelType());
        bizResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        bizResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editMchntFeeDiscountMcDetailResponse.setRespCode(RespCodeEnum.TRANS_SUCCESS.getRespCode());
        editMchntFeeDiscountMcDetailResponse.setRespDesc(RespCodeEnum.TRANS_SUCCESS.getRespDesc());

        editMchntFeeDiscountMcDetailResponse.setMcNo(globalMcNo);

        bizResponse.setResult(editMchntFeeDiscountMcDetailResponse);

        return bizResponse;
    }

    /**
     * 营销活动信息数据库实体类和接口实体类数据转换
     *
     * @param mchntFeeDiscountMcInfoBean 商户手续费优惠类活动基本信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntFeeDiscountInfo 商户手续费优惠类营销活动信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 15:18
     */
    private TMMcMchntFeeDiscountInfo convertMcInfo(MchntFeeDiscountMcInfoBean mchntFeeDiscountMcInfoBean) throws Exception {

        // 检查上传字段 不能为负数
        checkMcInfoObjFieldHasNegativeNumber(mchntFeeDiscountMcInfoBean);

        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = new TMMcMchntFeeDiscountInfo();

        /* 法人机构号 */
        tmMcMchntFeeDiscountInfo.setInstId(globalInstId);
        /* 营销活动编号 */
        tmMcMchntFeeDiscountInfo.setMcNo(globalMcNo);
        /* 营销活动名称 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcName())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setMcName(mchntFeeDiscountMcInfoBean.getMcName());
        }
        /* 营销活动类型 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcType())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setMcType(mchntFeeDiscountMcInfoBean.getMcType());
        }
        /* 营销活动状态 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcStatus())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setMcStatus(mchntFeeDiscountMcInfoBean.getMcStatus());
        }
        /* 活动起始日期 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcStartDate())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setMcStartDate(mchntFeeDiscountMcInfoBean.getMcStartDate());
        }
        /* 活动截止日期 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcEndDate())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setMcEndDate(mchntFeeDiscountMcInfoBean.getMcEndDate());
        }
        /* 活动结束日期 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getMcActualEndDate())) {
            /* 需要计算营销活动实际结束日期 */
            if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntFlag())) {

                if (CommonConstant.MCHNT_NEW_FLAG.equals(mchntFeeDiscountMcInfoBean.getNewMchntFlag())) {
                    /* 支持新增商户，营销活动实际结束日期应该与新增商户顺延最后日期相同 */

                    if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntPeriod())) {
                        throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                    }

                    //免手续费周期
                    int monthPeriod = Integer.parseInt(mchntFeeDiscountMcInfoBean.getNewMchntPeriod());
                    String actualEndDate = MompDateUtil.getFutureMonAddOneFirstDay(mchntFeeDiscountMcInfoBean.getMcEndDate(), monthPeriod);
                    //判断是否支持新商户顺延
                    String postponeFlag = mchntFeeDiscountMcInfoBean.getPostponeFlag();
                    if (CommonConstant.NEW_MCHNT_DISCOUNT_PROLONG.equals(postponeFlag)) {
                        tmMcMchntFeeDiscountInfo.setMcActualEndDate(actualEndDate);
                    } else {
                        tmMcMchntFeeDiscountInfo.setMcActualEndDate(mchntFeeDiscountMcInfoBean.getMcEndDate());
                    }

                } else {
                    /* 不支持新增商户，营销活动实际结束日期应该与活动截止日期相同 */
                    tmMcMchntFeeDiscountInfo.setMcActualEndDate(mchntFeeDiscountMcInfoBean.getMcEndDate());
                }
            } else {
                /* 必输标志未设置，默认不支持新增商户，营销活动实际结束日期应该与活动截止日期相同 */
                tmMcMchntFeeDiscountInfo.setMcActualEndDate(mchntFeeDiscountMcInfoBean.getMcEndDate());
            }

        } else {
            /* 不需要计算，直接使用接口上送内容 */
            tmMcMchntFeeDiscountInfo.setMcActualEndDate(mchntFeeDiscountMcInfoBean.getMcActualEndDate());
        }

        /*存量商户达标条件 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getStockMchntFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setStockMchntFlag(mchntFeeDiscountMcInfoBean.getStockMchntFlag());

            if (CommonConstant.MFD_STOCK_MCHNT_CFG.equals(mchntFeeDiscountMcInfoBean.getStockMchntFlag())) {
                /*存量商户支持类型 */
                if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getStockMchntType())) {
                    tmMcMchntFeeDiscountInfo.setStockMchntType(mchntFeeDiscountMcInfoBean.getStockMchntType());
                }
                /*有效交易下限 */
                if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getEffectiveLimit())) {
                    tmMcMchntFeeDiscountInfo.setEffectiveLimit(MompAmountUtil.getTwoDecimal(mchntFeeDiscountMcInfoBean.getEffectiveLimit()));
                }
            } else {
                /*存量商户支持类型 */
                if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getStockMchntType())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMchntFeeDiscountInfo.setStockMchntType(mchntFeeDiscountMcInfoBean.getStockMchntType());
                }
                /*有效交易下限 */
                if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getEffectiveLimit())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMchntFeeDiscountInfo.setEffectiveLimit(MompAmountUtil.getTwoDecimal(mchntFeeDiscountMcInfoBean.getEffectiveLimit()));
                }
            }
        }

        /*新增商户支持标志 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setNewMchntFlag(mchntFeeDiscountMcInfoBean.getNewMchntFlag());

            if (CommonConstant.MCHNT_NEW_FLAG.equals(mchntFeeDiscountMcInfoBean.getNewMchntFlag())) {

                /*新增商户免手续费周期 */
                if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntPeriod())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMchntFeeDiscountInfo.setNewMchntPeriod(mchntFeeDiscountMcInfoBean.getNewMchntPeriod());
                }
                /*新增商户周期顺延标志 */
                if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getPostponeFlag())) {
                    throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                } else {
                    tmMcMchntFeeDiscountInfo.setPostponeFlag(mchntFeeDiscountMcInfoBean.getPostponeFlag());
                }

            } else {
                /*新增商户免手续费周期 */
                if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntPeriod())) {
                    tmMcMchntFeeDiscountInfo.setNewMchntPeriod(mchntFeeDiscountMcInfoBean.getNewMchntPeriod());
                }
                /*新增商户周期顺延标志 */
                if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getPostponeFlag())) {
                    tmMcMchntFeeDiscountInfo.setPostponeFlag(mchntFeeDiscountMcInfoBean.getPostponeFlag());
                }
            }
        }

        /*达标前手续费优惠规则 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getBeforeFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setBeforeFlag(mchntFeeDiscountMcInfoBean.getBeforeFlag());
        }
        /*达标后手续费优惠规则 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getAfterFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setAfterFlag(mchntFeeDiscountMcInfoBean.getAfterFlag());
        }
        /*优惠退出标志 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getTerminationFlag())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setTerminationFlag(mchntFeeDiscountMcInfoBean.getTerminationFlag());
        }
        /*统计周期 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getStatPeriod())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setStatPeriod(mchntFeeDiscountMcInfoBean.getStatPeriod());
        }
        /*单个商户优惠交易笔数上限 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getQuantityLimit())) {
            tmMcMchntFeeDiscountInfo.setQuantityLimit(CommonConstant.ZERO_COMMON_CONSTANT);
        } else {
            tmMcMchntFeeDiscountInfo.setQuantityLimit(mchntFeeDiscountMcInfoBean.getQuantityLimit());
        }
        /*单个商户优惠交易金额上限 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getAmountLimit())) {
            tmMcMchntFeeDiscountInfo.setAmountLimit(CommonConstant.ZERO_AMOUNT);
        } else {
            tmMcMchntFeeDiscountInfo.setAmountLimit(MompAmountUtil.getTwoDecimal(mchntFeeDiscountMcInfoBean.getAmountLimit()));
        }
        /*单个商户手续费优惠额上限 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getFeeLimit())) {
            tmMcMchntFeeDiscountInfo.setFeeLimit(CommonConstant.ZERO_AMOUNT);
        } else {
            tmMcMchntFeeDiscountInfo.setFeeLimit(MompAmountUtil.getTwoDecimal(mchntFeeDiscountMcInfoBean.getFeeLimit()));
        }
        /* 预算充值方式 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getBudgetRechargeMethod())) {
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        } else {
            tmMcMchntFeeDiscountInfo.setBudgetRechargeMethod(mchntFeeDiscountMcInfoBean.getBudgetRechargeMethod());
        }
        /* 预算 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getBudget())) {
            tmMcMchntFeeDiscountInfo.setBudget(CommonConstant.ZERO_AMOUNT);
        } else {
            tmMcMchntFeeDiscountInfo.setBudget(MompAmountUtil.getTwoDecimal(mchntFeeDiscountMcInfoBean.getBudget()));
        }
        /* 审批状态-待提交审批状态 */
        tmMcMchntFeeDiscountInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
        /* 活动发布批量任务状态 */
        tmMcMchntFeeDiscountInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_INITIAL);
        /* 创建人 */
        tmMcMchntFeeDiscountInfo.setOprId(globalOprId);
        /* 创建时间 */
        tmMcMchntFeeDiscountInfo.setCreateTime(globalTimeStamp);
        /* 最后修改人 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getLastOprId())) {
            tmMcMchntFeeDiscountInfo.setLastOprId(mchntFeeDiscountMcInfoBean.getLastOprId());
        }
        /* 修改时间 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getUpdateTime())) {
            tmMcMchntFeeDiscountInfo.setUpdateTime(mchntFeeDiscountMcInfoBean.getUpdateTime());
        }
        /* 审批拒绝原因 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getAuditRefuseReason())) {
            tmMcMchntFeeDiscountInfo.setAuditRefuseReason(mchntFeeDiscountMcInfoBean.getAuditRefuseReason());
        }
        /* 发布拒绝原因 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getPublishRefuseReason())) {
            tmMcMchntFeeDiscountInfo.setPublishRefuseReason(mchntFeeDiscountMcInfoBean.getPublishRefuseReason());
        }
        /* 备用字段1 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getRemark1())) {
            tmMcMchntFeeDiscountInfo.setRemark1(mchntFeeDiscountMcInfoBean.getRemark1());
        }
        /* 备用字段2 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getRemark2())) {
            tmMcMchntFeeDiscountInfo.setRemark2(mchntFeeDiscountMcInfoBean.getRemark2());
        }
        /* 备用字段3 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getRemark3())) {
            tmMcMchntFeeDiscountInfo.setRemark3(mchntFeeDiscountMcInfoBean.getRemark3());
        }
        /* 备用字段4 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getRemark4())) {
            tmMcMchntFeeDiscountInfo.setRemark4(mchntFeeDiscountMcInfoBean.getRemark4());
        }
        /* 备用字段5 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getRemark5())) {
            tmMcMchntFeeDiscountInfo.setRemark5(mchntFeeDiscountMcInfoBean.getRemark5());
        }
        /* 月均存款平均月数 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getDepositMonNum())) {
            tmMcMchntFeeDiscountInfo.setDepositMonNum(mchntFeeDiscountMcInfoBean.getDepositMonNum());
        } else {
            tmMcMchntFeeDiscountInfo.setDepositMonNum(CommonConstant.ONE_COMMON_CONSTANT);
        }
        /* 创建机构 */
        if (!StringUtil.isNullorEmpty(globalOrgId)) {
            tmMcMchntFeeDiscountInfo.setCrtOrgId(globalOrgId);
        }
        if (mchntFeeDiscountMcInfoBean.getStockMchntFlag().equals(CommonConstant.STOCK_MCHNT_FLAG_ZERO)
                && mchntFeeDiscountMcInfoBean.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG)) {
            tmMcMchntFeeDiscountInfo.setPublishBatchStatus(CommonConstant.PUBLISH_BATCH_SUCCESS);
        }
        //新增商户免交易金额上限
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntAmountLimit())) {
            tmMcMchntFeeDiscountInfo.setNewMchntAmountLimit(mchntFeeDiscountMcInfoBean.getNewMchntAmountLimit());
        } else {
            if (CommonConstant.MCHNT_NEW_FLAG.equals(mchntFeeDiscountMcInfoBean.getNewMchntFlag())) {
                tmMcMchntFeeDiscountInfo.setNewMchntAmountLimit(CommonConstant.BIG_NUMBER);
            }
        }
        /*活动支持商户类型 如果上传了，则使用上传的，没有上传则默认所有商户都支持*/
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getAvySprtMrctTyp())) {
            tmMcMchntFeeDiscountInfo.setavySprtMrctTyp(mchntFeeDiscountMcInfoBean.getAvySprtMrctTyp());
        } else {
            tmMcMchntFeeDiscountInfo.setavySprtMrctTyp(CommonConstant.SUPPORT_ALLTYPES_MCHNT);
        }

        /* 新增商户免费额度类型 */
        if (StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getNewMchntAmountType())) {
            //没有上传默认免费额度类型为0   0：免费额度为免交易金额   目前外放的接口没有添加此字段，故创建的活动仍为交易金额
            tmMcMchntFeeDiscountInfo.setNewmrctFreeLmtTyp(CommonConstant.ZERO_COMMON_CONSTANT);
        } else {
            tmMcMchntFeeDiscountInfo.setNewmrctFreeLmtTyp(mchntFeeDiscountMcInfoBean.getNewMchntAmountType());
        }

        return tmMcMchntFeeDiscountInfo;
    }

    /**
     * 营销活动机构信息数据库实体类和接口实体类数据转换
     *
     * @param mcOrgInfoBean 营销活动机构信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcOrgInfo 营销活动机构信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:11
     */
    private TMMcOrgInfo convertMcOrgInfo(McOrgInfoBean mcOrgInfoBean) {
        TMMcOrgInfo mcOrgInfo = new TMMcOrgInfo();
        try {
            /* 法人机构号 */
            mcOrgInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcOrgInfo.setMcNo(globalMcNo);
            /* 机构编号 */
            mcOrgInfo.setOrgId(mcOrgInfoBean.getOrgId());
            /* 机构层级 */
            mcOrgInfo.setOrgHierarchy(mcOrgInfoBean.getOrgHierarchy());
            /* 机构名称 */
            mcOrgInfo.setOrgName(mcOrgInfoBean.getOrgName());
            /* 创建人 */
            mcOrgInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcOrgInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动机构信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcOrgInfo;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:10
     */
    private TMMcMchntInfo convertMcMchntInfo(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 操作类型 */
            mcMchntInfo.setOprType(mcMchntInfoBean.getOprType());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);


        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动规则信息数据库实体类和接口实体类数据转换
     *
     * @param mchntFeeDiscountRuleInfoBean 商户手续费优惠类营销活动规则信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntFeeDiscountRuleInfo 商户手续费优惠类营销活动规则表
     * @author Jinan Liu
     * @since 2020/4/1 21:07
     */
    private TMMcMchntFeeDiscountRuleInfo convertMcRuleInfo(MchntFeeDiscountRuleInfoBean mchntFeeDiscountRuleInfoBean) {
        // 检查上传字段 不能为负数
        checkRuleInfoFieldHasNegativeNumber(mchntFeeDiscountRuleInfoBean);

        TMMcMchntFeeDiscountRuleInfo tmMcMchntFeeDiscountRuleInfo = new TMMcMchntFeeDiscountRuleInfo();

        try {
            /* 法人机构号 */
            tmMcMchntFeeDiscountRuleInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            tmMcMchntFeeDiscountRuleInfo.setMcNo(globalMcNo);
            /* 顺序号  */
            tmMcMchntFeeDiscountRuleInfo.setRuleIndex(mchntFeeDiscountRuleInfoBean.getRuleIndex());
            if (!globalStockMchntType.equals(CommonConstant.OLD_MCHNT_TXN_QTY)) {
                /* 优惠力度下限 */
                tmMcMchntFeeDiscountRuleInfo.setCriteriaFloor(MompAmountUtil.getTwoDecimal(mchntFeeDiscountRuleInfoBean.getCriteriaFloor()));
                /* 优惠力度上限 */
                tmMcMchntFeeDiscountRuleInfo.setCriteriaCelling(MompAmountUtil.getTwoDecimal(mchntFeeDiscountRuleInfoBean.getCriteriaCelling()));
            } else {
                /* 优惠力度下限 */
                tmMcMchntFeeDiscountRuleInfo.setCriteriaFloor(mchntFeeDiscountRuleInfoBean.getCriteriaFloor());
                /* 优惠力度上限 */
                tmMcMchntFeeDiscountRuleInfo.setCriteriaCelling(mchntFeeDiscountRuleInfoBean.getCriteriaCelling());
            }
            if (globalStockMchntType.equals(CommonConstant.OLD_MCHNT_DEPOSIT)) {
                /* 优惠周期 */
                tmMcMchntFeeDiscountRuleInfo.setDiscountPeriod(CommonConstant.MFD_PERIOD_MONTH);
            } else {
                /* 优惠周期 */
                tmMcMchntFeeDiscountRuleInfo.setDiscountPeriod(mchntFeeDiscountRuleInfoBean.getDiscountPeriod());
            }
            /* 优惠类型 */
            tmMcMchntFeeDiscountRuleInfo.setDiscountType(mchntFeeDiscountRuleInfoBean.getDiscountType());
            if (CommonConstant.ZERO_COMMON_CONSTANT.equals(mchntFeeDiscountRuleInfoBean.getDiscountType())) {
                /* 优惠力度 */
                tmMcMchntFeeDiscountRuleInfo.setDiscount(CommonConstant.ZERO_AMOUNT);
            } else {
                /* 优惠力度 */
                tmMcMchntFeeDiscountRuleInfo.setDiscount(mchntFeeDiscountRuleInfoBean.getDiscount());
            }
            /* 计算规则编号 */
            tmMcMchntFeeDiscountRuleInfo.setCalRuleNo(mchntFeeDiscountRuleInfoBean.getCalRuleNo());
            /* 优惠上限 */
            if (!StringUtil.isNullorEmpty(mchntFeeDiscountRuleInfoBean.getDiscountLimit())) {
                tmMcMchntFeeDiscountRuleInfo.setDiscountLimit(MompAmountUtil.getTwoDecimal(mchntFeeDiscountRuleInfoBean.getDiscountLimit()));
            }
            /* 创建人 */
            tmMcMchntFeeDiscountRuleInfo.setOprId(globalOprId);
            /* 创建时间 */
            tmMcMchntFeeDiscountRuleInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动规则信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return tmMcMchntFeeDiscountRuleInfo;
    }

    /**
     * 营销活动支付产品信息数据库实体类和接口实体类数据转换
     *
     * @param mcProductInfoBean 营销活动产品对象
     * @return cc.rengu.igas.momp.common.entity.TMMcProductInfo 营销活动产品信息表
     * @author Jinan Liu
     * @since 2020/4/1 21:06
     */
    private TMMcProductInfo convertMcProductInfo(McProductInfoBean mcProductInfoBean) {
        TMMcProductInfo mcProductInfo = new TMMcProductInfo();
        try {
            /* 法人机构号 */
            mcProductInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcProductInfo.setMcNo(globalMcNo);
            /* 业务产品代码 */
            mcProductInfo.setBizProdCode(mcProductInfoBean.getBizProdCode());
            /* 创建人 */
            mcProductInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcProductInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动支付产品信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcProductInfo;
    }

    /**
     * 新增营销活动信息
     *
     * @param dbsUtil                             数据为操作工具类
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:48
     */
    private void insertAllMcInfoByBank(DbsUtil dbsUtil, EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        /* 营销活动基本信息新增 */
        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = convertMcInfo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());
        /** 上传商户文件，活动审批状态修改为中间态 */
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowAuditStatus = tmMcMchntFeeDiscountInfo.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmMcMchntFeeDiscountInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
        }
        insertMfdMcInfo(dbsUtil, tmMcMchntFeeDiscountInfo);
        TMPlatBizTmp tmPlatBizTmp = convertMfdMcInfoToTmp(tmMcMchntFeeDiscountInfo);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowTmpAuditStatus = tmPlatBizTmp.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
            auditStatusChangeFlag = true;
        }
        insertTmpMfdMcInfo(dbsUtil, tmPlatBizTmp);

        /* 营销活动机构信息新增 */
        List<TMMcOrgInfo> mcOrgInfoList = editMchntFeeDiscountMcDetailRequest.getOrgInfoList().stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);

        /* 营销活动商户信息新增 */
        /** 判断是否存在文件，存在则创建任务流水 */
        if (merFileFlag) {
            rglog.info("法人机构<{}>的营销活动<{}>同步创建营销活动任务信息!", globalInstId, globalMcNo);
            insertMcTaskInfoForMerFile(dbsUtil, editMchntFeeDiscountMcDetailRequest.getMrctFilePath());
        } else {

            List<TMMcMchntInfo> tmMcMchntInfoList = editMchntFeeDiscountMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());

            /* 上传商户信息，需要判断商户新增/删除 */
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户/商圈列表，size<{}>", globalInstId, globalMcNo, tmMcMchntInfoList.size());
            //商户列表，增量处理方式
            List<TMMcMchntInfo> mcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ZERO_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户列表，size<{}>", globalInstId, globalMcNo, mcMchntInfoList.size());

            /* 删除商户列表 */
            List<TMMcMchntInfo> delTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.DELETE.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delTmMcMchntList.size());
            deleteMcMchntInfoList(dbsUtil, delTmMcMchntList);
            List<TMPlatBizTmp> delMcMchntList = delTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delMcMchntList);

            /* 新增商户列表 */
            List<TMMcMchntInfo> addTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.INSERT.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表，size<{}>", globalInstId, globalMcNo, addTmMcMchntList.size());
            insertMcMchntInfo(dbsUtil, addTmMcMchntList);
            List<TMPlatBizTmp> addTmpMchntList = addTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表临时表，size<{}>", globalInstId, globalMcNo, addTmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, addTmpMchntList);

            /* 商圈列表，全量处理方式 */
            List<TMMcMchntInfo> tradeAreatList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ONE_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表，size<{}>", globalInstId, globalMcNo, tradeAreatList.size());
            insertMcMchntInfo(dbsUtil, tradeAreatList);
            List<TMPlatBizTmp> tmpMchntList = tradeAreatList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表临时表，size<{}>", globalInstId, globalMcNo, tmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);
        }

        /* 营销活动规则信息新增 */
        List<TMMcMchntFeeDiscountRuleInfo> tmMcMchntFeeDiscountRuleInfoList = editMchntFeeDiscountMcDetailRequest.getRuleInfoList().stream().map(this::convertMcRuleInfo).collect(Collectors.toList());
        insertMfdRuleInfoListByBank(dbsUtil, tmMcMchntFeeDiscountRuleInfoList);
        List<TMPlatBizTmp> tmpMfdMcRuleList = tmMcMchntFeeDiscountRuleInfoList.stream().map(this::convertMfdMcRuleInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMfdMcRuleList);

        /* 营销活动产品信息新增 */
        List<TMMcProductInfo> mcProductInfoList = editMchntFeeDiscountMcDetailRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);

    }


    /**
     * 保存数据流程
     *
     * @param xmlTreeUtil                         内部XML树
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020-06-29 18:50
     */
    private void saveAllMcInfoByBank(XmlTreeUtil xmlTreeUtil, EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        int returnCode;

        /* 营销活动信息正式表查询 */
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmMcMchntFeeDiscountInfo) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_MCHNT_FEE_DISCOUNT_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MCHNT_FEE_DISCOUNT_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 营销活动信息临时表查询 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        TMPlatBizTmp tmPlatBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TABLE_NAME);
        if (null == tmPlatBizTmp) {
            rglog.error("法人机构<{}>的营销活动<{}>的信息不存在!");
            throw new BizException(RespCodeEnum.GET_MCHNT_FEE_DISCOUNT_MC_DETAIL_ERROR.getRespCode(), RespCodeEnum.GET_MCHNT_FEE_DISCOUNT_MC_DETAIL_ERROR.getRespDesc());
        }

        /* 数据库有历史数据，需要判断历史数据状态 */

        /* 判断营销活动是否存在进行中跑批任务 */
        if (AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode().equals(tmMcMchntFeeDiscountInfo.getAuditStatus())) {
            /* 营销活动审批状态异常，不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>，存在跑批任务，不可保存数据!", globalInstId, globalMcNo, tmMcMchntFeeDiscountInfo.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }

        /* 判断营销活动审批状态 */
        if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus()) &&
                !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(tmPlatBizTmp.getAuditStatus())) {
            /* 营销活动审批状态异常，不可保存数据 */
            rglog.error("法人机构<{}>的营销活动<{}>的审批状态<{}>异常，不可保存数据!", globalInstId, globalMcNo, tmPlatBizTmp.getAuditStatus());
            throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
        }

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        String tmpAuditStatus = tmPlatBizTmp.getAuditStatus();
        String tmpMcStatus = tmPlatBizTmp.getMcStatus();
        String tmpBizStatus = tmPlatBizTmp.getBizStatus();

        String auditStatus = tmMcMchntFeeDiscountInfo.getAuditStatus();
        String mcStatus = tmMcMchntFeeDiscountInfo.getMcStatus();

        if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(mcStatus)) {
            /* 正式表营销活动状态是进行中，说明是进行中活动添加商户流程，只更新临时表数据 */
            updateAllDraftMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);

        } else {
            /* 正式表营销活动状态不是进行中，正式表临时表一起更新 */
            updateAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);

            /* 更新定时任务流水业务数据 */
            if (merFileFlag) {

                /* 更新临时表除活动信息外其他信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcOtherStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmpBizStatus, tmpMcStatus, tmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 备份活动表、临时表业务数据，跑批完成后进行状态还原操作 */
                /* 更新流水表业务数据 */
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", auditStatus);
                bizDate.put("tmpAuditStatus", tmpAuditStatus);
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-1,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                //变更活动表、临时表审批状态为中间态
                auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }

                /* 更新临时表活动信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcInfoStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                        tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

            } else {
                /* 更新临时表审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcAllStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, tmpBizStatus, tmpMcStatus, tmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }
            /* 更新正式表审批状态 */
            TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo1 = new TMMcMchntFeeDiscountInfo();
            tmMcMchntFeeDiscountInfo1.setInstId(globalInstId);
            tmMcMchntFeeDiscountInfo1.setMcNo(globalMcNo);
            tmMcMchntFeeDiscountInfo1.setMcStatus(mcStatus);
            tmMcMchntFeeDiscountInfo1.setAuditStatus(auditStatus);
            tmMcMchntFeeDiscountInfo1.setLastOprId(globalOprId);
            tmMcMchntFeeDiscountInfo1.setUpdateTime(globalTimeStamp);

            returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMchntFeeDiscountInfo1, TABLE_NAME);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 更新正式表中营销活动审批状态失败 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
            }
        }

        /* 正常结束数据库事务 */
        dbsUtil.dbsEndTransaction(true);
    }

    /**
     * 更新营销活动信息
     *
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/2 00:13
     */
    private void updateAllMcInfoByBank(DbsUtil dbsUtil, EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        rglog.info("法人机构<{}>的营销活动<{}>删除临时表数据，仅保留商户信息");
        int returnCode = platBizTmpMapper.deleteTmpMcDataRetainMchntListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 删除临时表数据失败 */
            dbsUtil.dbsEndTransaction(false);
            rglog.error("删除临时表中营销活动各信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            throw new BizException(RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_TMP_MC_DATA_ERROR.getRespDesc());
        }
        /* 营销活动信息更新 */
        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = convertMcInfo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());
        deleteMfdMcInfo(dbsUtil);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowAuditStatus = tmMcMchntFeeDiscountInfo.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmMcMchntFeeDiscountInfo.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
        }
        insertMfdMcInfo(dbsUtil, tmMcMchntFeeDiscountInfo);
        TMPlatBizTmp tmPlatBizTmp = convertMfdMcInfoToTmp(tmMcMchntFeeDiscountInfo);
        if (merFileFlag) {
            /** 备份当前活动审批状态 */
            flowTmpAuditStatus = tmPlatBizTmp.getAuditStatus();
            /* 调整审批状态为任务处理中 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode());
            auditStatusChangeFlag = true;
        }
        insertTmpMfdMcInfo(dbsUtil, tmPlatBizTmp);

        /* 处理因机构变更需要清除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editMchntFeeDiscountMcDetailRequest.getOrgInfoList());
        /* 营销活动机构信息更新 */
        List<TMMcOrgInfo> mcOrgInfoList = editMchntFeeDiscountMcDetailRequest.getOrgInfoList().stream().map(this::convertMcOrgInfo).collect(Collectors.toList());
        deleteMcOrgInfo(dbsUtil);
        insertMcOrgInfo(dbsUtil, mcOrgInfoList);
        List<TMPlatBizTmp> tmpOrgList = mcOrgInfoList.stream().map(this::convertMcOrgInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpOrgList);
        /* 营销活动商户信息更新 */
        if (merFileFlag) {
            /** 新增任务流水 */
            rglog.info("法人机构<{}>的营销活动<{}>同步创建营销活动任务信息!", globalInstId, globalMcNo);
            insertMcTaskInfoForMerFile(dbsUtil, editMchntFeeDiscountMcDetailRequest.getMrctFilePath());
        } else {
            List<TMMcMchntInfo> tmMcMchntInfoList = editMchntFeeDiscountMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfo).collect(Collectors.toList());

            rglog.info("法人机构<{}>的营销活动<{}>编辑商户/商圈列表，size<{}>", globalInstId, globalMcNo, tmMcMchntInfoList.size());
            /* 商户列表，增量处理方式 */
            List<TMMcMchntInfo> mcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ZERO_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>编辑商户列表，size<{}>", globalInstId, globalMcNo, mcMchntInfoList.size());

            /* 删除商户列表 */
            List<TMMcMchntInfo> delTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.DELETE.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delTmMcMchntList.size());
            deleteMcMchntInfoList(dbsUtil, delTmMcMchntList);
            List<TMPlatBizTmp> delMcMchntList = delTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delMcMchntList);

            /* 新增商户列表 */
            List<TMMcMchntInfo> addTmMcMchntList = mcMchntInfoList.stream().filter(item -> OprTypeEnum.INSERT.getOprTypeCode().equals(item.getOprType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表，size<{}>", globalInstId, globalMcNo, addTmMcMchntList.size());
            insertMcMchntInfo(dbsUtil, addTmMcMchntList);
            List<TMPlatBizTmp> addTmpMchntList = addTmMcMchntList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商户列表临时表，size<{}>", globalInstId, globalMcNo, addTmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, addTmpMchntList);

            /* 商圈列表，全量处理方式 */
            //删除原有商圈
            rglog.info("法人机构<{}>的营销活动<{}>删除下属所有商圈数据。", globalInstId, globalMcNo);
            deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);
            //新增商圈数据
            List<TMMcMchntInfo> tradeAreatList = tmMcMchntInfoList.stream().filter(item -> CommonConstant.ONE_COMMON_CONSTANT.equals(item.getMchntType())).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表，size<{}>", tradeAreatList.size());
            insertMcMchntInfo(dbsUtil, tradeAreatList);
            List<TMPlatBizTmp> tmpMchntList = tradeAreatList.stream().map(this::convertMcMchntInfoToTmp).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>保存商圈列表临时表，size<{}>", tmpMchntList.size());
            insertMultiMcDetialInfoByBank(dbsUtil, tmpMchntList);

        }
        /* 营销活动规则信息更新 */
        List<TMMcMchntFeeDiscountRuleInfo> tmMcMchntFeeDiscountRuleInfoList = editMchntFeeDiscountMcDetailRequest.getRuleInfoList().stream().map(this::convertMcRuleInfo).collect(Collectors.toList());
        deleteMcMoRuleInfo(dbsUtil);
        insertMfdRuleInfoListByBank(dbsUtil, tmMcMchntFeeDiscountRuleInfoList);
        List<TMPlatBizTmp> tmpMfdMcRuleList = tmMcMchntFeeDiscountRuleInfoList.stream().map(this::convertMfdMcRuleInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpMfdMcRuleList);
        /* 营销活动产品信息更新 */
        List<TMMcProductInfo> mcProductInfoList = editMchntFeeDiscountMcDetailRequest.getProductInfoList().stream().map(this::convertMcProductInfo).collect(Collectors.toList());
        deleteMcProductInfo(dbsUtil);
        insertMcProductInfo(dbsUtil, mcProductInfoList);
        List<TMPlatBizTmp> tmpProdList = mcProductInfoList.stream().map(this::convertMcProdInfoToTmp).collect(Collectors.toList());
        insertMultiMcDetialInfoByBank(dbsUtil, tmpProdList);
    }

    /**
     * 提交营销活动信息
     *
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/6 17:43
     */
    private void submitMcInfo(EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        int returnCode = 0;
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();

        rglog.info("提交审批流程开始");

        /* 营销活动信息正式表查询 */
        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = null;
        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();

//        TMMcMchntFeeDiscountInfo mcMchntFeeDiscountInfo = convertMcInfo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());

        if (StringUtil.isNullorEmpty(globalMcNo)) {
            rglog.info("上送数据无营销活动编号!新增后提交审批流程开始!");
        } else {
            tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
        }

        /* 营销活动信息临时表查询 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        TMPlatBizTmp platBizTmp = platBizTmpMapper.selectTmpMcInfo(globalInstId, globalMcNo, TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());

        /* 开启数据库事务 */
        String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppConfigConstant.DATABASE_CONF_NODE, AppConfigConstant.MOMP_POOL_NAME);
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MOMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolName);
        dbsUtil.dbsBeginTransaction();

        if (null == tmMcMchntFeeDiscountInfo && null == platBizTmp) {

            /* 数据库无历史数据，新增提交审批场景，新增数据后直接提交审批 */

            /*
             * 如果营销活动编号不存在，说明是全新的营销活动，需要生成一个营销活动编号，并新增全部数据；
             * 如果营销活动编号存在，说明是接口调用错误，需要返回失败信息；
             */
            if (StringUtil.isNullorEmpty(globalMcNo)) {
                /* 生成营销活动编号 */
                globalMcNo = generateNewMcNo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());
                if (!StringUtil.isNullorEmpty(globalMcNo)) {
                    rglog.info("MC_NO=<{}>", globalMcNo);
                }

                /* 全部新增流程，插入数据 */
                rglog.info("提交审批新增流程开始");
                insertAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);

            } else {
                /* 全部更新流程，更新数据 */
                rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());
            }

            String auditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
            String tmpAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
            /* 更新定时任务流水业务数据 */
            if (merFileFlag) {
                /* 更新临时表除活动信息外其他信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcOtherAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 备份活动表、临时表业务数据，跑批完成后进行状态还原操作 */
                JSONObject bizDate = new JSONObject();
                bizDate.put("auditStatus", auditStatus);
                bizDate.put("tmpAuditStatus", tmpAuditStatus);
                rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-2,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                /* 更新任务表业务数据信息 */
                updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                //变更活动表、临时表审批状态为中间态
                auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();

                String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                if (auditStatusChangeFlag) {
                    oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                }

                /* 更新临时表活动信息审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcInfoAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                        oldAuditStatus, tmpAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 更新正式表审批状态 */
                returnCode = mcDetailInfoMapper.updateMfdMcAuditStatusByPrimaryKeyForTask(globalInstId, globalMcNo, auditStatus);
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

            } else {
                /* 更新临时表审批状态 */
                returnCode = platBizTmpMapper.updateTmpMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode(), BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新临时表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                }

                /* 更新正式表审批状态 */
                returnCode = mcDetailInfoMapper.updateMfdMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                if (Database.DBS_SUCCESS != returnCode) {
                    /* 更新正式表中营销活动审批状态失败 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                    throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                }
            }
            /* 正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else if (null != tmMcMchntFeeDiscountInfo && null != platBizTmp) {
            /* 数据库有历史数据，需要判断历史数据状态 */

            /* 判断营销活动审批状态 */
            if (!AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()) &&
                    !AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) {
                /* 不可提交审批状态 */
                rglog.error("营销活动是不可提交审批状态,不可提交审批, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_AUDIT_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 判断业务状态 */
            if (BizStatusEnum.TMP_STATUS.getBizStatusCode().equals(platBizTmp.getBizStatus())) {
                if (!McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) &&
                        !McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(platBizTmp.getMcStatus())) {
                    /* 营销活动状态异常，不可提交审批 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("营销活动状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getMcStatus(), globalMcNo);
                    throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
                } else {
                    /* 新增提交审批场景 */

                    /*
                     * 如果营销活动编号不存在，说明数据异常，不可提交审批；
                     * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；
                     */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 全部更新流程，更新数据 */
                        rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());

                    } else {
                        /* 全部更新流程，更新数据 */
                        updateAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);
                    }

                    String newAuditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
                    String auditStatus = AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode();
                    if ((McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) && AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus())) || (McStatusEnum.DRAFT.getMcStatusCode().equals(platBizTmp.getMcStatus()) && AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode().equals(platBizTmp.getAuditStatus()))) {
                        newAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                        auditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                    }

                    String tmpAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                    /* 更新定时任务流水业务数据 */
                    if (merFileFlag) {
                        /* 更新临时表除活动信息外其他信息审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcOtherAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                                tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }
                        /* 备份活动表、临时表业务数据，跑批完成后进行状态还原操作 */
                        //备份更新后活动审批状态
                        JSONObject bizDate = new JSONObject();
                        bizDate.put("auditStatus", auditStatus);
                        bizDate.put("tmpAuditStatus", newAuditStatus);
                        rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-3,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                        /* 更新流水表业务数据 */
                        /* 更新任务表业务数据信息 */
                        updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                        //变更活动表、临时表审批状态为中间态
                        auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                        newAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();

                        if (auditStatusChangeFlag) {
                            tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                        }

                        /* 更新临时表活动信息审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcInfoAuditStatusByPrimaryKey(globalInstId, globalMcNo, TABLE_NAME,
                                tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                        /* 更新正式表审批状态 */
                        returnCode = mcDetailInfoMapper.updateMfdMcAuditStatusByPrimaryKeyForTask(globalInstId, globalMcNo, auditStatus);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                    } else {
                        /* 更新临时表审批状态 */
                        returnCode = platBizTmpMapper.updateTmpMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, tmpAuditStatus, newAuditStatus, BizStatusEnum.TMP_STATUS.getBizStatusCode(), McStatusEnum.DRAFT.getMcStatusCode());
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新临时表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                        /* 更新正式表审批状态 */
                        returnCode = mcDetailInfoMapper.updateMfdMcAuditStatusByPrimaryKey(globalInstId, globalMcNo, auditStatus);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }
                    }

                }

            } else if (BizStatusEnum.NORMAL_STATUS.getBizStatusCode().equals(platBizTmp.getBizStatus())) {
                if (McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(platBizTmp.getMcStatus()) && McStatusEnum.NOT_PUBLISHED.getMcStatusCode().equals(tmMcMchntFeeDiscountInfo.getMcStatus())) {
                    /* 修改提交审批场景 */
                    /*
                     * 如果营销活动编号不存在，说明数据异常，不可提交审批；
                     * 如果营销活动编号存在，说明是正常的新增提交审批场景，可以提交审批；
                     */
                    if (StringUtil.isNullorEmpty(globalMcNo)) {
                        /* 全部更新流程，更新数据 */
                        rglog.error("当前营销活动<{}>不可保存数据!", globalMcNo);
                        dbsUtil.dbsEndTransaction(false);
                        throw new BizException(RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespCode(), RespCodeEnum.NO_AVAILABLE_DATA_TO_PROCESS_ERROR.getRespDesc());

                    } else {
                        /* 全部更新流程，更新数据 */
//                        String tmpAuditStatus = platBizTmp.getAuditStatus();
                        String tmpMcStatus = platBizTmp.getMcStatus();
                        String tmpBizStatus = platBizTmp.getBizStatus();

//                        String auditStatus = tmMcMchntFeeDiscountInfo.getAuditStatus();
//                        String mcStatus = tmMcMchntFeeDiscountInfo.getMcStatus();

                        updateAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);
                        String tmpAuditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                        String auditStatus = AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode();
                        if (merFileFlag) {
                            /* 更新临时表审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcOtherStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                                    tmpBizStatus, tmpMcStatus, tmpAuditStatus, AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动其他信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }
                            /* 备份活动表、临时表业务数据，跑批完成后进行状态还原操作 */
                            /* 更新流水表业务数据 */
                            JSONObject bizDate = new JSONObject();
                            bizDate.put("auditStatus", auditStatus);
                            bizDate.put("tmpAuditStatus", tmpAuditStatus);
                            rglog.info("交易流水号：<{}>,任务流水号<{}>,switch-4,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());
                            /* 更新任务表业务数据信息 */
                            updateMcTaskInfoBizDate(dbsUtil, globalInstId, globalMcNo, globalFlowNo, bizDate.toString());

                            //变更活动表、临时表审批状态为中间态
                            auditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                            tmpAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();

                            String oldAuditStatus = AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode();
                            if (auditStatusChangeFlag) {
                                oldAuditStatus = AuditStatusEnum.WAIT_FOR_DEALING.getAuditStatusCode();
                            }

                            /* 更新临时表活动信息审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcInfoStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, TABLE_NAME,
                                    tmpBizStatus, tmpMcStatus, tmpAuditStatus, oldAuditStatus, globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动活动信息审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }

                        } else {
                            /* 更新临时表审批状态 */
                            returnCode = platBizTmpMapper.updateTmpMcAllStatusByMcNoAndAuditStatus(globalInstId, globalMcNo, tmpBizStatus, tmpMcStatus, AuditStatusEnum.MODIFY_AUDIT_PROCESSING.getAuditStatusCode(), AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode(), globalOprId, globalTimeStamp);
                            if (Database.DBS_SUCCESS != returnCode) {
                                /* 更新临时表中营销活动审批状态失败 */
                                dbsUtil.dbsEndTransaction(false);
                                rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                                throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                            }
                        }
                        /* 更新正式表审批状态 */
                        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo1 = new TMMcMchntFeeDiscountInfo();
                        tmMcMchntFeeDiscountInfo1.setInstId(globalInstId);
                        tmMcMchntFeeDiscountInfo1.setMcNo(globalMcNo);
                        tmMcMchntFeeDiscountInfo1.setMcStatus(McStatusEnum.NOT_PUBLISHED.getMcStatusCode());
                        tmMcMchntFeeDiscountInfo1.setAuditStatus(auditStatus);
                        tmMcMchntFeeDiscountInfo1.setLastOprId(globalOprId);
                        tmMcMchntFeeDiscountInfo1.setUpdateTime(globalTimeStamp);

                        returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMchntFeeDiscountInfo1, TABLE_NAME);
                        if (Database.DBS_SUCCESS != returnCode) {
                            /* 更新正式表中营销活动审批状态失败 */
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                            throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                        }

                    }
                } else if (McStatusEnum.PROGRESSING.getMcStatusCode().equals(platBizTmp.getMcStatus()) && McStatusEnum.PROGRESSING.getMcStatusCode().equals(tmMcMchntFeeDiscountInfo.getMcStatus())) {
                    /* 活动中添加商户场景 */
                    //判断是否上传商户文件
                    if (merFileFlag) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("进行中营销活动禁止上传商户文件!");
                        throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
                    }
                    //判断上送的商户信息是否已经存在
                    McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                    //取正式表进行中新增的商户
                    List<TMMcMchntInfo> tmMcMchntInfoListing = mcMchntInfoMapper.selectMcMchntInfoList(globalInstId, globalMcNo);
                    //编辑或新增上送的商户信息
                    List<TMMcMchntInfo> tmMcMchntInfoList = editMchntFeeDiscountMcDetailRequest.getMchntInfoList().stream().map(this::convertMcMchntInfos).collect(Collectors.toList());
                    //要删除的商户List
                    List<TMMcMchntInfo> deleteMchntList;
                    deleteMchntList = tmMcMchntInfoListing;
                    for (TMMcMchntInfo tmMcMchntInfo : tmMcMchntInfoList) {
                        deleteMchntList = deleteMchntList.stream().filter(item -> !item.getMchntNo().equals(tmMcMchntInfo.getMchntNo())).collect(Collectors.toList());
                    }
                    //正式表删除商户信息
                    for (TMMcMchntInfo tmMcMchntInfo : deleteMchntList) {
                        returnCode = mcMchntInfoMapper.deleteMchntInfo(tmMcMchntInfo.getInstId(), tmMcMchntInfo.getMcNo(), tmMcMchntInfo.getMchntNo());
                        if (Database.DBS_SUCCESS != returnCode) {
                            dbsUtil.dbsEndTransaction(false);
                            rglog.error("正式表删除商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, tmMcMchntInfo.getMcNo());
                            throw new BizException(RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc());
                        }
                    }
                    //临时表删除商户信息
                    List<TMPlatBizTmp> deletetmPlatBizTmpList = deleteMchntList.stream().map(this::convertMcMchntInfoToTmps).collect(Collectors.toList());
                    returnCode = platBizTmpMapper.deleteByMcNoMchntNoTablename(deletetmPlatBizTmpList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("临时删除商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespCode(), RespCodeEnum.DELETE_MC_MCHNT_DATA_ERROR.getRespDesc());
                    }
                    //要新增的商户list
                    List<TMMcMchntInfo> newMchntList = new ArrayList<>();
                    newMchntList = tmMcMchntInfoList;
                    for (TMMcMchntInfo tmMcMchntInfo : tmMcMchntInfoListing) {
                        newMchntList = newMchntList.stream().filter(item -> !item.getMchntNo().equals(tmMcMchntInfo.getMchntNo())).collect(Collectors.toList());
                    }
                    //插入正式表新增商户
                    returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(newMchntList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("正式表插入新增商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespCode(), RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespDesc());
                    }
                    //插入临时表新增商户
                    List<TMPlatBizTmp> tmPlatBizTmpList = newMchntList.stream().map(this::convertMcMchntInfoToTmps).collect(Collectors.toList());
                    returnCode = platBizTmpMapper.insertMchntDataForUnderwayMc(tmPlatBizTmpList);
                    if (Database.DBS_SUCCESS != returnCode) {
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("临时表插入新增商户失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespCode(), RespCodeEnum.WRONG_UPDATEMCMCHNT_ERROR.getRespDesc());
                    }
                    /* 更新临时表审批状态 */
                    /* 修改临时表营销活动状态 */
                    TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
                    tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
                    tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
                    tmPlatBizTmp.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                    tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MFD_INFO.getTableNameDesc());
                    tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
                    returnCode = platBizTmpMapper.updataTMPlatBizByinstIdMcNoTableNameAuditStatus(globalInstId, globalMcNo, tmPlatBizTmp, platBizTmp.getAuditStatus(), globalOprId, new SimpleDateFormat(CommonConstant.TIMESTAMP_FORMAT).format(new Date()));
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新临时表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新临时表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_TMP_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }
                    /* 更新正式表审批状态 */
                    TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo1 = new TMMcMchntFeeDiscountInfo();
                    tmMcMchntFeeDiscountInfo1.setInstId(globalInstId);
                    tmMcMchntFeeDiscountInfo1.setMcNo(globalMcNo);
                    tmMcMchntFeeDiscountInfo1.setMcStatus(McStatusEnum.PROGRESSING.getMcStatusCode());
                    tmMcMchntFeeDiscountInfo1.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
                    tmMcMchntFeeDiscountInfo1.setLastOprId(globalOprId);
                    tmMcMchntFeeDiscountInfo1.setUpdateTime(globalTimeStamp);

                    returnCode = mcDetailInfoMapper.updateMcStatusForPublishing(tmMcMchntFeeDiscountInfo1, TABLE_NAME);
                    if (Database.DBS_SUCCESS != returnCode) {
                        /* 更新正式表中营销活动审批状态失败 */
                        dbsUtil.dbsEndTransaction(false);
                        rglog.error("更新正式表中营销活动审批状态失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
                        throw new BizException(RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespCode(), RespCodeEnum.UPDATE_MC_STATUS_FAILED_ERROR.getRespDesc());
                    }
                } else {
                    /* 营销活动状态异常，不可提交审批 */
                    dbsUtil.dbsEndTransaction(false);
                    rglog.error("营销活动状态异常，不可提交审批, MC_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getMcStatus(), globalMcNo);
                    throw new BizException(RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_MC_STATUS_TO_SUBMIT_ERROR.getRespDesc());
                }
            } else {
                /* 临时表状态异常，不可提交审批 */
                dbsUtil.dbsEndTransaction(false);
                rglog.error("营销活动临时数据状态异常，不可提交审批, BIZ_STATUS=<{}>, MC_NO=<{}>", platBizTmp.getBizStatus(), globalMcNo);
                throw new BizException(RespCodeEnum.WRONG_TMP_BIZ_STATUS_TO_SUBMIT_ERROR.getRespCode(), RespCodeEnum.WRONG_TMP_BIZ_STATUS_TO_SUBMIT_ERROR.getRespDesc());
            }

            /* 正常结束数据库事务 */
            dbsUtil.dbsEndTransaction(true);

        } else {
            /* 异常结束数据库事务 */
            rglog.error("查询营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 更新营销活动信息
     * 修改草稿流程使用
     *
     * @param editMchntFeeDiscountMcDetailRequest 商户手续费优惠类营销活动信息编辑接口请求对象
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/4/2 00:13
     */
    private void updateAllDraftMcInfoByBank(DbsUtil dbsUtil, EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();
        tmPlatBizTmp.setInstId(globalInstId);
        tmPlatBizTmp.setMcNo(globalMcNo);
        tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
        tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
        tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());

        /* 删错指定营销活动编号的所有草稿状态的数据数据 */
        deleteAllDraftMcInfoByBank(dbsUtil);

        /* 处理因机构变更需要清除的商户数据 */
        delMchntListByDelOrgList(dbsUtil, editMchntFeeDiscountMcDetailRequest.getOrgInfoList());
//        TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = convertMcInfo(editMchntFeeDiscountMcDetailRequest.getMcInfoObj());
        deleteMfdMcInfo(dbsUtil);
        deleteMcOrgInfo(dbsUtil);
        /* 保留商户数据，删除商圈数据*/
        //deleteMcMchntInfo(dbsUtil);
        deleteMcMchntAreat(dbsUtil, CommonConstant.ONE_COMMON_CONSTANT);
        deleteMcMoRuleInfo(dbsUtil);
        deleteMcProductInfo(dbsUtil);

        insertAllMcInfoByBank(dbsUtil, editMchntFeeDiscountMcDetailRequest);
    }

    /**
     * 生成营销活动编号
     *
     * @param moneyOffMcInfoBean 商户手续费优惠类活动基本信息对象
     * @return java.lang.String
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 14:57
     */
    private String generateNewMcNo(MchntFeeDiscountMcInfoBean moneyOffMcInfoBean) throws Exception {

        // MC+2位营销活动类型+1位出资方+8位活动起始日期+8位活动截止日期+11位sequence
        MompSequenceMapper mompSequenceMapper = new MompSequenceMapperImpl();

        String mcNoSuffix = mompSequenceMapper.getMompNextMaNoSeq();

        return "MC" + moneyOffMcInfoBean.getMcType() + CommonConstant.SPONSOR_BANK + moneyOffMcInfoBean.getMcStartDate() + moneyOffMcInfoBean.getMcEndDate() + mcNoSuffix;
    }


    /**
     * 插入商户手续费优惠类营销活动基本信息
     *
     * @param dbsUtil                  数据库操作工具类
     * @param tmMcMchntFeeDiscountInfo 商户手续费优惠类营销活动信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:35
     */
    private void insertMfdMcInfo(DbsUtil dbsUtil, TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.insertSingleMfdMcInfo(tmMcMchntFeeDiscountInfo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将商户手续费优惠类营销活动基本信息插入临时表中
     *
     * @param dbsUtil      数据库操作工具类
     * @param tmPlatBizTmp 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/22 15:39
     */
    private void insertTmpMfdMcInfo(DbsUtil dbsUtil, TMPlatBizTmp tmPlatBizTmp) throws Exception {

        /* 数据入库 */
        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMcInfoByBank(tmPlatBizTmp);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 商户手续费优惠类营销活动信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntFeeDiscountInfo 商户手续费优惠类营销活动信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/22 11:49
     */
    private TMPlatBizTmp convertMfdMcInfoToTmp(TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntFeeDiscountInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntFeeDiscountInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MFD_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMfdMcInfoTmpBizData1(tmMcMchntFeeDiscountInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动机构信息表
     *
     * @param dbsUtil       数据库操作工具类
     * @param mcOrgInfoList 营销活动机构信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:38
     */
    private void insertMcOrgInfo(DbsUtil dbsUtil, List<TMMcOrgInfo> mcOrgInfoList) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.insertMcOrgInfoListByBank(mcOrgInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 将营销活动机构信息插入临时表中
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/28 22:17
     */
    private void insertMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.insertMultiMcDetialInfoByBank(tmPlatBizTmpList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动机构信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcOrgInfo 营销活动机构信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:12
     */
    private TMPlatBizTmp convertMcOrgInfoToTmp(TMMcOrgInfo tmMcOrgInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcOrgInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcOrgInfo.getMcNo());
            /* 机构编号 */
            tmPlatBizTmp.setOrgId(tmMcOrgInfo.getOrgId());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_ORG_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcOrgInfoTmpBizData1(tmMcOrgInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动商户信息
     *
     * @param dbsUtil         数据库操作工具类
     * @param mcMchntInfoList 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:05
     */
    private void insertMcMchntInfo(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.insertMcMchntInfoListByBank(mcMchntInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动商户信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmp(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);
            /* 存储商户范围类型 */
            tmPlatBizTmp.setRemark1(tmMcMchntInfo.getMchntType());
            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动商户手续费优惠类规则信息
     *
     * @param dbsUtil                          数据库操作工具类
     * @param tmMcMchntFeeDiscountRuleInfoList 商户手续费优惠类营销活动规则表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private void insertMfdRuleInfoListByBank(DbsUtil dbsUtil, List<TMMcMchntFeeDiscountRuleInfo> tmMcMchntFeeDiscountRuleInfoList) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.insertMfdRuleInfoListByBank(tmMcMchntFeeDiscountRuleInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动商户手续费优惠类规则信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动规则信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcMchntFeeDiscountRuleInfo 商户手续费优惠类营销活动规则表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMfdMcRuleInfoToTmp(TMMcMchntFeeDiscountRuleInfo tmMcMchntFeeDiscountRuleInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntFeeDiscountRuleInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntFeeDiscountRuleInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MFD_RULE_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MFD_RULE_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMfdMcRuleInfoTmpBizData1(tmMcMchntFeeDiscountRuleInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 插入营销活动产品信息
     *
     * @param dbsUtil           数据库操作工具类
     * @param mcProductInfoList 营销活动产品信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:08
     */
    private void insertMcProductInfo(DbsUtil dbsUtil, List<TMMcProductInfo> mcProductInfoList) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.insertMcProductInfoListByBank(mcProductInfoList);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动产品信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 营销活动产品信息表数据转换
     * 正式表数据转换为临时表数据
     *
     * @param tmMcProductInfo 营销活动产品信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author Jinan Liu
     * @since 2020/5/28 22:49
     */
    private TMPlatBizTmp convertMcProdInfoToTmp(TMMcProductInfo tmMcProductInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcProductInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcProductInfo.getMcNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_PROD_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcProdInfoTmpBizData1(tmMcProductInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.WAIT_FOR_SUBMIT.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 删除商户手续费优惠类营销活动基本信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:35
     */
    private void deleteMfdMcInfo(DbsUtil dbsUtil) throws Exception {

        McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
        int returnCode = mcDetailInfoMapper.deleteMfdMcInfo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动机构信息表
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 16:38
     */
    private void deleteMcOrgInfo(DbsUtil dbsUtil) throws Exception {

        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        int returnCode = mcOrgInfoMapper.deleteMcOrgInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动机构信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:05
     */
    private void deleteMcMchntInfo(DbsUtil dbsUtil) throws Exception {

        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMcMchntInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动商户手续费优惠类规则信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:15
     */
    private void deleteMcMoRuleInfo(DbsUtil dbsUtil) throws Exception {

        McRuleInfoMapper mcRuleInfoMapper = new McRuleInfoMapperImpl();
        int returnCode = mcRuleInfoMapper.deleteMfdRuleInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户手续费优惠类规则信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动产品信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/21 18:08
     */
    private void deleteMcProductInfo(DbsUtil dbsUtil) throws Exception {

        McProductInfoMapper mcProductInfoMapper = new McProductInfoMapperImpl();
        int returnCode = mcProductInfoMapper.deleteMcProductInfoListByBank(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动产品信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删错指定营销活动编号的所有草稿状态的数据数据
     * 保留商户临时表数据
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @since 2020/5/28 23:12
     */
    private void deleteAllDraftMcInfoByBank(DbsUtil dbsUtil) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteTmpMcDataRetainMchntListByMcNo(globalInstId, globalMcNo);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除草稿状态营销活动临时表数据失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 校验接口上送的商户信息和机构信息是否匹配
     *
     * @throws Exception 异常信息
     * @author liujinan
     * @date 2020/7/14 14:00
     */
    private void checkMchntAndOrgInfo(EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {

        traceNo = editMchntFeeDiscountMcDetailRequest.getHeader().getTraceNo();

        List<McOrgInfoBean> orgInfoList = editMchntFeeDiscountMcDetailRequest.getOrgInfoList();
        List<McMchntInfoBean> mchntInfoList = editMchntFeeDiscountMcDetailRequest.getMchntInfoList();
        if (null == orgInfoList || orgInfoList.isEmpty()) {
            rglog.error("交易流水号：<{}>, 接口请求上送的营销活动机构信息为空", traceNo);
            throw new BizException(RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.GET_MC_ORG_INFO_ERROR.getRespDesc());
        }


        List<String> mchntRealOrgList = new ArrayList<>();
        List<String> requestOrgList = new ArrayList<>();

        String mchntType, mchntNo;
        MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
        TBTradeAreaInfoMapper tbTradeAreaInfoMapperImpl = new TBTradeAreaInfoMapperImpl();
        OrganizationMapper organizationMapper = new OrganizationMapperImpl();
        //获取当前时间
        String date = DateUtil.getCurrentDate();


        if (merFileFlag) {
            rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户文件路径：<{}>，暂不校验商户及机构是否匹配，流程继续...", traceNo, editMchntFeeDiscountMcDetailRequest.getMrctFilePath());
        } else {
            if (null == mchntInfoList || mchntInfoList.isEmpty()) {
                rglog.info("交易流水号：<{}>, 接口请求上送的营销活动商户信息为空，不校验商户及机构是否匹配，流程继续...", traceNo);
            } else {
                int maxSize = mchntInfoList.size();
                for (int i = 0; i < maxSize; i++) {
                    McMchntInfoBean mcMchntInfoBean = mchntInfoList.get(i);
                    //商户类型
                    mchntType = mcMchntInfoBean.getMchntType();
                    //商户范围号
                    mchntNo = mcMchntInfoBean.getMchntNo();

                    if (CommonConstant.ZERO_COMMON_CONSTANT.equals(mchntType)) {
                        /** 增加操作类型节点非空校验 */
                        String oprType = mcMchntInfoBean.getOprType();
                        if (StringUtil.isNullorEmpty(oprType)) {
                            rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点未上送！", traceNo, mchntNo, oprType);
                            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo);
                        }

                        rglog.info("交易流水号：<{}>, 查询商户<{}>信息开始...", traceNo, mchntNo);

                        //查询商户基本信息
                        TBMchntBaseInfo tbMchntBaseInfo = mchntInfoMapper.selectMchntBaseInfoByMchntNo(globalInstId, mchntNo);
                        if (null == tbMchntBaseInfo) {
                            rglog.error("交易流水号：<{}>, 商户<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespCode(), RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespDesc() + ",商户号" + mchntNo);
                        }

                        /** 存量营销活动筛选上传的商户列表，去除oprType=I已存在的商户、去除oprType=D不存在的商户 */
                        if (!StringUtil.isNullorEmpty(globalMcNo)) {
                            rglog.info("校验接口上送的新增/删除商户列表报文是否冗余");
                            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
                            TMMcMchntInfo mchntInfo = mcMchntInfoMapper.selectTMMcMchntInfoByPrimaryKey(globalInstId, globalMcNo, mchntNo);
                            if (OprTypeEnum.INSERT.getOprTypeCode().equals(oprType)) {
                                if (null != mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>新增操作校验不通过，该商户已存在，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else if (OprTypeEnum.DELETE.getOprTypeCode().equals(oprType)) {
                                if (null == mchntInfo) {
                                    rglog.info("交易流水号：<{}>, 商户列表数据<{}>删除操作校验不通过，该商户不存在无法删除，跳过该商户继续流程！", traceNo, mchntNo);
                                    mchntInfoList.remove(mcMchntInfoBean);
                                    maxSize--;
                                    i--;
                                    continue;
                                }
                            } else {
                                rglog.error("交易流水号：<{}>, 商户列表数据<{}>操作类型<{}>节点值上送错误！", traceNo, mchntNo, oprType);
                                throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc() + ",商户号" + mchntNo + "操作类型节点值上送错误");
                            }
                        }
                        mchntRealOrgList.add(tbMchntBaseInfo.getSignInstId());
                        //判断商户是否存在特殊费率，如果有则不允许进行下一步
                        List<TBMchntFeeInfo> tbMchntFeeInfoList = mchntInfoMapper.selectMchntFeeInfoListByMchntNo(globalInstId, mchntNo);
                        if (null != tbMchntFeeInfoList && tbMchntFeeInfoList.size() > 0) {
                            tbMchntFeeInfoList = tbMchntFeeInfoList.stream().filter(item -> item.getFeeInputMode().equals(CommonConstant.ZERO_COMMON_CONSTANT)).collect(Collectors.toList());
                            if (tbMchntFeeInfoList.size() > 0) {
                                rglog.error("交易流水号：<{}>, 商户<{}>费率信息表存在特殊费率！", traceNo, mchntNo);
                                throw new BizException(RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespCode(), RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespDesc());
                            }
                        }
                        //查询手续费达标统计表是否有该商户现交易日期达标的数据
                        TMStatMfdCriteriaMapper tmStatMfdCriteriaMapper = new TMStatMfdCriteriaMapperImpl();
                        TMStatMfdCriteria tmStatMfdCriteria = tmStatMfdCriteriaMapper.selectTMStatMfdCriteriaByUsingMchntNoAndDateRange(globalInstId, mchntNo, date);
                        if (null != tmStatMfdCriteria) {
                            /* 营销活动信息正式表查询 */
                            McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
                            TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, tmStatMfdCriteria.getMcNo(), TABLE_NAME);
                            //如果达标统计表有当前交易日期商户达标的数据，则直接拒绝新增,原活动状态为自然结束，强制结束，已结束的数据作废
                            if (null != tmMcMchntFeeDiscountInfo && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                                rglog.error("交易流水号：<{}>, 商户<{}>已参加其他手续费活动<{}>！", traceNo, mchntNo, tmMcMchntFeeDiscountInfo.getMcNo());
                                throw new BizException(RespCodeEnum.WRONG_MCHNT_ISALREADY_ORTHER_INMC_ERROR.getRespCode(), RespCodeEnum.WRONG_MCHNT_ISALREADY_ORTHER_INMC_ERROR.getRespDesc());
                            }
                        }
                    } else if (CommonConstant.ONE_COMMON_CONSTANT.equals(mchntType)) {
                        rglog.info("交易流水号：<{}>, 查询商圈<{}>信息开始...", traceNo, mchntNo);
                        //查询商圈基本信息
                        TBTradeAreatInfo TBTradeAreatInfo = tbTradeAreaInfoMapperImpl.selectTradeAreaInfoByTradeAreaCode(globalInstId, mchntNo);
                        if (null == TBTradeAreatInfo) {
                            rglog.error("交易流水号：<{}>, 商圈<{}>信息查询异常！", traceNo, mchntNo);
                            throw new BizException(RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespCode(), RespCodeEnum.GET_MCHNT_BASE_INFO_ERROR_BY_FORMAL.getRespDesc() + ",商圈号" + mchntNo);
                        }
                        mchntRealOrgList.add(TBTradeAreatInfo.getBelongInstId());
                        //查询商圈下的所有商户
                        List<TBMchntBaseInfo> tbMchntBaseInfoList = mchntInfoMapper.selectMchntBaseInfoListByMchntArea(globalInstId, mchntNo);
                        if (null != tbMchntBaseInfoList && !tbMchntBaseInfoList.isEmpty()) {
                            for (TBMchntBaseInfo tbMchntBaseInfo : tbMchntBaseInfoList) {
                                //判断商户是否存在特殊费率，如果有则不允许进行下一步
                                List<TBMchntFeeInfo> tbMchntFeeInfoList = mchntInfoMapper.selectMchntFeeInfoListByMchntNo(globalInstId, tbMchntBaseInfo.getMchntNo());
                                if (null != tbMchntFeeInfoList && tbMchntFeeInfoList.size() > 0) {
                                    tbMchntFeeInfoList = tbMchntFeeInfoList.stream().filter(item -> item.getFeeInputMode().equals(CommonConstant.ZERO_COMMON_CONSTANT)).collect(Collectors.toList());
                                    if (tbMchntFeeInfoList.size() > 0) {
                                        rglog.error("交易流水号：<{}>, 商圈<{}>下商户<{}>费率信息表存在特殊费率！", traceNo, mchntNo, tbMchntBaseInfo.getMchntNo());
                                        throw new BizException(RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespCode(), RespCodeEnum.EXISTENCE_SPECIAL_FEE.getRespDesc());
                                    }
                                }
                                //查询手续费达标统计表是否有该商户现交易日期达标的数据
                                TMStatMfdCriteriaMapper tmStatMfdCriteriaMapper = new TMStatMfdCriteriaMapperImpl();
                                TMStatMfdCriteria tmStatMfdCriteria = tmStatMfdCriteriaMapper.selectTMStatMfdCriteriaByUsingMchntNoAndDateRange(globalInstId, tbMchntBaseInfo.getMchntNo(), date);
                                if (null != tmStatMfdCriteria) {
                                    /* 营销活动信息正式表查询 */
                                    McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
                                    TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(globalInstId, tmStatMfdCriteria.getMcNo(), TABLE_NAME);
                                    //如果达标统计表有当前交易日期商户达标的数据，则直接拒绝新增,原活动状态为自然结束，强制结束，已结束的数据作废
                                    if (null != tmMcMchntFeeDiscountInfo && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                                        rglog.error("交易流水号：<{}>,商圈<{}>下 商户<{}>已参加其他手续费活动<{}>！", traceNo, mchntNo, tbMchntBaseInfo.getMchntNo(), tmMcMchntFeeDiscountInfo.getMcNo());
                                        throw new BizException(RespCodeEnum.WRONG_MCHNT_ISALREADY_ORTHER_INMC_ERROR.getRespCode(), RespCodeEnum.WRONG_MCHNT_ISALREADY_ORTHER_INMC_ERROR.getRespDesc());
                                    }
                                }
                            }
                        }
                    } else {
                        rglog.error("交易流水号：<{}>, 接口请求上送的商户类型错误...", traceNo);
                        throw new BizException(RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespCode(), RespCodeEnum.WRONG_MC_MCHNTTYPE.getRespDesc());
                    }
                }

                //对请求上送的商户所属的机构进行去重处理
                mchntRealOrgList = mchntRealOrgList.stream().distinct().collect(Collectors.toList());

                //处理接口请求上送的机构信息
                List<String> requestOrgIdList = orgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
                //对请求上送的机构进行去重处理
                requestOrgIdList = requestOrgIdList.stream().distinct().collect(Collectors.toList());

                //比较通过接口上送的机构号是否包含通过商户筛选出的机构号
                if (requestOrgIdList.containsAll(mchntRealOrgList)) {
                    rglog.info("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息校验通过！", traceNo);
                } else {
                    rglog.error("交易流水号：<{}>, 接口上送的机构信息与商户所属机构信息失败！", traceNo);
                    throw new BizException(RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespCode(), RespCodeEnum.CHECK_MCHNTREALORG_REQUESTORG_FAIL.getRespDesc());
                }
            }
        }

        /* 接口上送的机构信息中不包含当前机构所属的上级机构，所以需要把上属机构补充道机构信息表中*/
        //需要从接口上送的机构信息中添加的上级机构
        List<McOrgInfoBean> addOrgIdList = new ArrayList<>();
        //最终机构信息（补充完上级机构后的机构列表）
        List<McOrgInfoBean> requestResultOrgList = editMchntFeeDiscountMcDetailRequest.getOrgInfoList();

        String queryOrgId = editMchntFeeDiscountMcDetailRequest.getQueryOrgId();
        //查询当前登录用户的所属机构信息
        Organization queryOrgInfo = organizationMapper.selectOrganization(globalInstId, queryOrgId);
        //当前登录用户所属机构的最大深度
        int orgLevealDepth = 6;
        Boolean superOrgFlag = false;
        while (orgLevealDepth > 0) {
            if (null != queryOrgInfo) {
                if (superOrgFlag) {
                    McOrgInfoBean mcOrgInfoBean = new McOrgInfoBean();
                    mcOrgInfoBean.setOrgHierarchy(queryOrgInfo.getOrgLevel());
                    mcOrgInfoBean.setOrgId(queryOrgInfo.getOrgCode());
                    mcOrgInfoBean.setOrgName(queryOrgInfo.getOrgName());
                    mcOrgInfoBean.setOprType(CommonConstant.DEFAULT_OPR_ID);
                    addOrgIdList.add(mcOrgInfoBean);
                }
                String superOrgId = queryOrgInfo.getSuperOrgCode();
                String orgLevel = queryOrgInfo.getOrgLevel();
                rglog.info("交易流水号：<{}>,当前机构机构编码<{}>,上级机构编码<{}>,机构编码级别<{}>", traceNo, queryOrgInfo.getOrgCode(), superOrgId, orgLevel);

                if (null != superOrgId && !"00".equals(orgLevel)) {
                    rglog.info("交易流水号：<{}>,接口请求上送的机构信息中需要添加 <{}>!", traceNo, superOrgId);
                    queryOrgInfo = organizationMapper.selectOrganization(globalInstId, superOrgId);
                    superOrgFlag = true;
                } else {
                    break;
                }

                orgLevealDepth--;
            } else {
                rglog.error("交易流水号：<{}>, 机构<{}>机构信息查询失败！", traceNo, addOrgIdList.size(), queryOrgId);
                throw new BizException(RespCodeEnum.NO_ORG_INFO_ERROR.getRespCode(), RespCodeEnum.NO_ORG_INFO_ERROR.getRespDesc());
            }
        }

        if (null != addOrgIdList && !addOrgIdList.isEmpty()) {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中有需要添加<{}>个上级机构信息", traceNo, addOrgIdList.size());
            requestResultOrgList.addAll(addOrgIdList);
            editMchntFeeDiscountMcDetailRequest.setOrgInfoList(requestResultOrgList);
        } else {
            rglog.info("交易流水号：<{}>, 接口上送的机构机构信息中不需要添加上级机构信息（当前用户所属机构已经为总行级别）", traceNo, addOrgIdList.size());
        }
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换(进行中新增商户)
     *
     * @param mcMchntInfoBean 营销活动商户信息对象
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author JL PANG
     * @since 2020/7/20
     */
    private TMMcMchntInfo convertMcMchntInfos(McMchntInfoBean mcMchntInfoBean) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(mcMchntInfoBean.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mcMchntInfoBean.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(mcMchntInfoBean.getMchntName());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_NEW_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 营销活动商户信息表数据转换
     * 正式表数据转换为临时表数据(进行中新增商户)
     *
     * @param tmMcMchntInfo 营销活动商户信息表
     * @return cc.rengu.igas.momp.common.entity.TMPlatBizTmp 业务数据临时表
     * @author JL Pang
     * @since 2020/5/28 22:26
     */
    private TMPlatBizTmp convertMcMchntInfoToTmps(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            //商户名称
            tmPlatBizTmp.setMchntName(tmMcMchntInfo.getMchntName());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作菜单 */
            tmPlatBizTmp.setOprMenuId(CommonConstant.DEFAULT_MENU_ID);
            /* 操作菜单名 */
            tmPlatBizTmp.setOprMenuName(CommonConstant.DEFAULT_MENU_NAME);
            /* 操作表中文名 */
            tmPlatBizTmp.setOprTableCname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameDesc());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());
            /* 操作 */
            tmPlatBizTmp.setBizOpr(BizOprEnum.INSERT.getBizOprCode());
            /* 新增商户标志 */
            tmMcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            tmMcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            tmMcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 数据域1 - 拼接JSON字符串 */
            tmPlatBizTmp.setBizData1(JsonOperation.packMcMchntInfoTmpBizData1(tmMcMchntInfo, rglog));
            /* 状态 */
            tmPlatBizTmp.setBizStatus(BizStatusEnum.TMP_STATUS.getBizStatusCode());
            /* 营销活动状态 */
            tmPlatBizTmp.setMcStatus(McStatusEnum.DRAFT.getMcStatusCode());
            /* 审批状态 */
            tmPlatBizTmp.setAuditStatus(AuditStatusEnum.NEW_AUDIT_PROCESSING.getAuditStatusCode());
            /* 创建人 */
            tmPlatBizTmp.setOprId(globalOprId);
            /* 创建时间 */
            tmPlatBizTmp.setCreateTime(globalTimeStamp);
            /* 存储商户范围类型 */
            tmPlatBizTmp.setRemark1(tmMcMchntInfo.getMchntType());

            return tmPlatBizTmp;

        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }

    /**
     * 断未上送商户号商圈号时，机构下的非特殊费率商户达标统计表是否存该交易日期内的数据
     *
     * @param editMchntFeeDiscountMcDetailRequest
     * @author JL Pang
     */
    private void checkMchntNoAndAreaNo(XmlTreeUtil xmlTreeUtil, EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {
        //法人机构号
        String instId = editMchntFeeDiscountMcDetailRequest.getHeader().getInstId();
        //当前活动开始日期
        String mcStartDate = editMchntFeeDiscountMcDetailRequest.getMcInfoObj().getMcStartDate();
        //取上送的商户信息
        List<McMchntInfoBean> mcMchntInfoBeanList = editMchntFeeDiscountMcDetailRequest.getMchntInfoList();
        McInfoListMapper mcInfoListMapper = new McInfoListMapperImpl();
        //查询当前日期内营销活动
        List<TMMcMchntFeeDiscountInfo> tmMcMchntFeeDiscountInfoList = mcInfoListMapper.selectMchntFeeDiscountMcListInfoForTime(instId, mcStartDate, "", "");
        //如果活动不存在，直接返回
        if (null == tmMcMchntFeeDiscountInfoList || tmMcMchntFeeDiscountInfoList.size() == 0) {
            return;
        }
        //循环取商户信息表存在该商户的活动
        for (McMchntInfoBean mcMchntInfoBean : mcMchntInfoBeanList) {
            //查询营销商户表数据
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            List<TMMcMchntInfo> tmMcMchntInfoList = mcMchntInfoMapper.selectMfdMchntInfoListByinstIdMchntNo(instId, mcMchntInfoBean.getMchntNo());
            if (null == tmMcMchntInfoList || tmMcMchntInfoList.size() == 0) {
                continue;
            }
            rglog.info("查询营销活动商户信息表数据该商户<{}>数据,共<{}>条", mcMchntInfoBean.getMchntNo(), tmMcMchntInfoList.size());
            tmMcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> item.getMcNo().contains("MC20")).collect(Collectors.toList());
            rglog.info("属于银行对商户手续费营销活动的条数<{}>", tmMcMchntInfoList.size());
            if (tmMcMchntInfoList.size() == 0) {
                continue;
            }
            tmMcMchntInfoList = tmMcMchntInfoList.stream().filter(item -> !item.getNewMchntFlag().equals(CommonConstant.MCHNT_REFUSE_FLAG) && !item.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG)).collect(Collectors.toList());
            rglog.info("符合银行对商户手续费营销活动的条数<{}>", tmMcMchntInfoList.size());
            if (tmMcMchntInfoList.size() == 0) {
                continue;
            }
            //上送商户是否参加了当前日期内其他进行中的手续费营销活动(new_mchnt_flag为1 exit_flag为1) (new_mchnt_flag为0 exit_flag为0)(new_mchnt_flag为0 exit_flag为1)
            List<TMMcMchntInfo> jxzMchntList = tmMcMchntInfoList.stream().filter(item -> (item.getNewMchntFlag().equals(CommonConstant.MCHNT_OLD_FLAG) && item.getExitFlag().equals(CommonConstant.MC_NOT_EXIT_FLAG)) || (item.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG) && item.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG))
                    || (item.getNewMchntFlag().equals(CommonConstant.MCHNT_OLD_FLAG) && item.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG))).collect(Collectors.toList());
            rglog.info("营销活动商户信息表状态为(new_mchnt_flag为1 exit_flag为1)或(new_mchnt_flag为0 exit_flag为0)或(new_mchnt_flag为0 exit_flag为1)的条数<{}>", jxzMchntList.size());
            if (jxzMchntList.size() > 0) {
                for (TMMcMchntInfo tmMcMchntInfo : jxzMchntList) {
                    /* 营销活动信息正式表查询 */
                    McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
                    TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(instId, tmMcMchntInfo.getMcNo(), TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
                    //如果活动状态不是自然结束，强制结束，草稿；审批状态不是新增拒绝，审批拒绝，发布拒绝的状态，直接抛异常
                    if (null != tmMcMchntFeeDiscountInfo && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())
                            && !tmMcMchntFeeDiscountInfo.getAuditStatus().equals(AuditStatusEnum.NEW_AUDIT_REJECT.getAuditStatusCode()) && !tmMcMchntFeeDiscountInfo.getAuditStatus().equals(AuditStatusEnum.MODIFY_AUDIT_REJECT.getAuditStatusCode()) && !tmMcMchntFeeDiscountInfo.getAuditStatus().equals(AuditStatusEnum.PUBLISH_AUDIT_REJECT.getAuditStatusCode())
                            && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.DRAFT.getMcStatusCode())) {
                        rglog.error("商户<{}>已参加其他进行中手续费活动<{}>！", tmMcMchntInfo.getMchntNo(), tmMcMchntFeeDiscountInfo.getMcNo());
                        throw new BizException(RespCodeEnum.WRONG_MCHNT_ISALREADY_INMC_ERROR.getRespCode(), RespCodeEnum.WRONG_MCHNT_ISALREADY_INMC_ERROR.getRespDesc() + ",商户<" + tmMcMchntInfo.getMchntNo() + ">");
                    }
                }
            }
            //上送商户是否有从a活动到b活动的转移(new_mchnt_flag为2 exit_flag为2) (new_mchnt_flag为1 exit_flag为2)
            List<TMMcMchntInfo> zyMchntList = tmMcMchntInfoList.stream().filter(item -> (item.getNewMchntFlag().equals(CommonConstant.MCHNT_REFUSE_FLAG) && item.getExitFlag().equals(CommonConstant.MC_TRANSFER_FLAG)) || (item.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG) && item.getExitFlag().equals(CommonConstant.MC_TRANSFER_FLAG))).collect(Collectors.toList());
            rglog.info("营销活动商户信息表状态为(new_mchnt_flag为2 exit_flag为2)或(new_mchnt_flag为1 exit_flag为2)的条数<{}>", zyMchntList.size());
            if (zyMchntList.size() > 0) {
                for (TMMcMchntInfo tmMcMchntInfo : zyMchntList) {
                    /* 营销活动信息正式表查询 */
                    McDetailInfoMapper mcDetailInfoMapper = new McDetailInfoMapperImpl();
                    TMMcMchntFeeDiscountInfo tmMcMchntFeeDiscountInfo = (TMMcMchntFeeDiscountInfo) mcDetailInfoMapper.selectMcDetailInfo(instId, tmMcMchntInfo.getMcNo(), TableNameEnum.T_M_MC_MFD_INFO.getTableNameCode());
                    if (null != tmMcMchntFeeDiscountInfo && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.FORCE_ENDED.getMcStatusCode()) && !tmMcMchntFeeDiscountInfo.getMcStatus().equals(McStatusEnum.ALL_ENDED.getMcStatusCode())) {
                        rglog.error("商户<{}>正在进行活动转移！", tmMcMchntInfo.getMchntNo(), tmMcMchntFeeDiscountInfo.getMcNo());
                        throw new BizException(RespCodeEnum.MCHNT_TRANSFER_WRONG.getRespCode(), RespCodeEnum.MCHNT_TRANSFER_WRONG.getRespDesc() + ",商户<" + tmMcMchntInfo.getMchntNo() + ">");
                    }
                }
            }
        }

    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param tbMchntBaseInfo 商户基本信息表
     * @return cc.rengu.igas.momp.common.entity.TBMchntBaseInfo 商户基本信息表
     * @author JL Pang
     * @since 2020/4/1 21:10
     */
    private TMMcMchntInfo convertMcMchntInfoByBaseInfo(TBMchntBaseInfo tbMchntBaseInfo) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(tbMchntBaseInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(tbMchntBaseInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfo.setMchntName(tbMchntBaseInfo.getMchntName());
            /* 新增商户标志 */
            mcMchntInfo.setNewMchntFlag(CommonConstant.MCHNT_OLD_FLAG);
            /* 退出标志 */
            mcMchntInfo.setExitFlag(CommonConstant.MC_NOT_EXIT_FLAG);
            /* 达标日期 */
            mcMchntInfo.setQualifiedDate(globalTxnDate);
            /* 创建人 */
            mcMchntInfo.setOprId(globalOprId);
            /* 创建时间 */
            mcMchntInfo.setCreateTime(globalTimeStamp);

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfo;
    }

    /**
     * 检查上送的营销活动规则是否相同
     *
     * @param editMchntFeeDiscountMcDetailRequest
     * @throws Exception
     */
    private void checkRuleInfo(EditMchntFeeDiscountMcDetailRequest editMchntFeeDiscountMcDetailRequest) throws Exception {
        List<MchntFeeDiscountRuleInfoBean> ruleInfoList = editMchntFeeDiscountMcDetailRequest.getRuleInfoList();
        //如果规则List不为空
        if (null != ruleInfoList && ruleInfoList.size() > 1) {
            //循环判断list优惠类型是否与第一个相同
            for (MchntFeeDiscountRuleInfoBean mchntFeeDiscountRuleInfoBean : ruleInfoList) {
                //如果不相同，则抛出错误
                if (!ruleInfoList.get(0).getDiscountType().equals(mchntFeeDiscountRuleInfoBean.getDiscountType())) {
                    rglog.error("营销活动规则存在不同优惠类型！");
                    throw new BizException(RespCodeEnum.WRONG_RULE_ISALREADY_ORTHER_INMC_ERROR.getRespCode(), RespCodeEnum.WRONG_RULE_ISALREADY_ORTHER_INMC_ERROR.getRespDesc());
                }
            }
        }

    }

    /**
     * 营销活动商户信息数据库实体类和上送接口实体类数据转换
     *
     * @param tbMchntBaseInfo 商户基本信息表
     * @return cc.rengu.igas.momp.common.entity.TBMchntBaseInfo 商户基本信息表
     * @author JL Pang
     * @since 2020/4/1 21:10
     */
    private McMchntInfoBean convertMcMchntBeanInfo(TBMchntBaseInfo tbMchntBaseInfo) {
        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        try {
            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(tbMchntBaseInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(tbMchntBaseInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(tbMchntBaseInfo.getMchntName());

        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }

        return mcMchntInfoBean;
    }

    /**
     * 检查 上送 营销活动信息 金额字段不能为负数
     *
     * @param mchntFeeDiscountMcInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkMcInfoObjFieldHasNegativeNumber(MchntFeeDiscountMcInfoBean mchntFeeDiscountMcInfoBean) {
        // 检查上传字段 不能为负数
        /* 单个商户优惠交易笔数上限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getQuantityLimit()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getQuantityLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单个商户优惠交易金额上限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getAmountLimit()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getAmountLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 单个商户手续费优惠额上限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getFeeLimit()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getFeeLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 预算 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getBudget()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getBudget()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 月均存款平均月数 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getDepositMonNum()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getDepositMonNum()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

        /* 有效交易下限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountMcInfoBean.getEffectiveLimit()) && new BigDecimal(mchntFeeDiscountMcInfoBean.getEffectiveLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
    }

    /**
     * 检查 上送 规则信息数据 金额字段不能为负数
     *
     * @param mchntFeeDiscountRuleInfoBean
     * @author ls
     * @date 2020/10/21
     */
    private void checkRuleInfoFieldHasNegativeNumber(MchntFeeDiscountRuleInfoBean mchntFeeDiscountRuleInfoBean) {
        /* 优惠力度下限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountRuleInfoBean.getCriteriaFloor()) && new BigDecimal(mchntFeeDiscountRuleInfoBean.getCriteriaFloor()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠力度上限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountRuleInfoBean.getCriteriaCelling()) && new BigDecimal(mchntFeeDiscountRuleInfoBean.getCriteriaCelling()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠力度 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountRuleInfoBean.getDiscount()) && new BigDecimal(mchntFeeDiscountRuleInfoBean.getDiscount()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }
        /* 优惠上限 */
        if (!StringUtil.isNullorEmpty(mchntFeeDiscountRuleInfoBean.getDiscountLimit()) && new BigDecimal(mchntFeeDiscountRuleInfoBean.getDiscountLimit()).compareTo(zero) < 0) {
            throw new BizException(RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespCode(), RespCodeEnum.FIELD_HAS_NEGATIVE_NUMBER.getRespDesc());
        }

    }

    /**
     * 新增商户定时任务
     *
     * @param dbsUtil
     * @param mrctFilePath 文件路径
     * @throws Exception
     * @author liujinan
     * @date 2021/06/07
     */
    private void insertMcTaskInfoForMerFile(DbsUtil dbsUtil, String mrctFilePath) throws Exception {
        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        TMMcTaskFlow flow = new TMMcTaskFlow();
        globalFlowNo = DateUtil.getCurrentDateTime("yyyyMMddHHmmssSSS") + RandomUtil.getRandomInt();
        /* 存储业务数据 */
        JSONObject bizDate = new JSONObject();
        bizDate.put("auditStatus", flowAuditStatus);
        bizDate.put("tmpAuditStatus", flowTmpAuditStatus);
        rglog.info("交易流水号：<{}>,任务流水号<{}>,新增任务流水,备份原营销活动审批状态<{}>", traceNo, globalFlowNo, bizDate.toString());

        flow.setFlowNo(globalFlowNo);
        flow.setInstId(globalInstId);
        flow.setMcNo(globalMcNo);
        flow.setBizTypeCd("");
        flow.setBizTypeParamData(bizDate.toJSONString());
        flow.setCreateTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setTaskSts("00");
        flow.setFilePath(mrctFilePath);
        flow.setTxnDt(DateUtil.getCurrentDate());
        flow.setTxnTm(DateUtil.getCurrentDateTime("yyyy-MM-dd HH:mm:ss.SSS"));
        flow.setOprId(globalOprId);
        flow.setRmrk1(traceNo);

        int returnCode = taskFlowMapper.insertMcTaskFlow(flow);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增活动上传商户文件定时任务失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
        rglog.info("创建商户文件定时任务");

    }

    /**
     * 修改任务表业务数据
     *
     * @param dbsUtil
     * @param instId  成员行编号
     * @param mcNo    活动编号
     * @param flowNo  任务流水号
     * @param bizDate 业务数据
     * @throws Exception
     * @author liujinan
     * @date 2021/06/07
     */
    private void updateMcTaskInfoBizDate(DbsUtil dbsUtil, String instId, String mcNo, String flowNo, String bizDate) throws Exception {

        McTaskFlowMapper taskFlowMapper = new McTaskFlowMapperImpl();
        int returnCode = taskFlowMapper.updateMcTaskFlowBizDate(instId, mcNo, flowNo, bizDate);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("更新商户文件定时任务业务数据失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
        rglog.info("更新商户文件定时任务业务数据，备份业务数据状态");
    }

    /**
     * 临时表中将营销活动指定商户信息删除
     *
     * @param dbsUtil          数据库操作工具类
     * @param tmPlatBizTmpList 业务数据临时表
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/5/28 22:17
     */
    private void deleteMultiMcDetialInfoByBank(DbsUtil dbsUtil, List<TMPlatBizTmp> tmPlatBizTmpList) throws Exception {

        PlatBizTmpMapper platBizTmpMapper = new PlatBizTmpMapperImpl();
        int returnCode = platBizTmpMapper.deleteMultiMcMchntListByBank(tmPlatBizTmpList);
        //兼容批量未新增临时表问题
        if (Database.DBS_SUCCESS != returnCode && Database.DBS_NOT_FOUND != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("新增营销活动机构信息失败, RETURN_CODE=<{}>, MC_NO=<{}>", returnCode, globalMcNo);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 删除营销活动指定商户信息
     *
     * @param dbsUtil 数据库操作工具类
     * @throws Exception 异常信息
     * @author liujinan
     * @since 2020/4/12 16:05
     */
    private void deleteMcMchntInfoList(DbsUtil dbsUtil, List<TMMcMchntInfo> mcMchntInfoList) throws Exception {
        if (!mcMchntInfoList.isEmpty()) {
            rglog.info("编辑营销活动删除商户信息列表size<{}>", mcMchntInfoList.size());
            McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
            int returnCode = mcMchntInfoMapper.deleteMcMchntInfoList(globalInstId, globalMcNo, mcMchntInfoList);
            if (Database.DBS_SUCCESS != returnCode) {
                /* 异常结束数据库事务 */
                rglog.error("删除营销活动商户信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>", returnCode, globalInstId, globalMcNo);
                dbsUtil.dbsEndTransaction(false);
                throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
            }
        } else {
            rglog.info("编辑营销活动删除商户信息列表无数据，MC_NO=<{}>", globalMcNo);
        }
    }

    /**
     * 删除营销活动商户/商圈信息
     *
     * @param dbsUtil
     * @param mchntType 商户类型0商户1商圈
     * @throws Exception
     */
    private void deleteMcMchntAreat(DbsUtil dbsUtil, String mchntType) throws Exception {
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        int returnCode = mcMchntInfoMapper.deleteMchntInfoByType(globalInstId, globalMcNo, mchntType);
        if (Database.DBS_SUCCESS != returnCode) {
            /* 异常结束数据库事务 */
            rglog.error("删除营销活动商户/商圈信息失败, RETURN_CODE=<{}>, INST_ID=<{}>, MC_NO=<{}>, MCHNT_TYPE=<{}>", returnCode, globalInstId, globalMcNo, mchntType);
            dbsUtil.dbsEndTransaction(false);
            throw new BizException(RespCodeEnum.DATABASE_OPR_ERROR.getRespCode(), RespCodeEnum.DATABASE_OPR_ERROR.getRespDesc());
        }
    }

    /**
     * 处理因机构变更导致需要删除的商户数据
     *
     * @param dbsUtil
     * @param orgInfoList 上传的机构列表信息
     * @throws Exception
     * @author liujinan
     * @since 2020/6/24 16:05
     */
    private void delMchntListByDelOrgList(DbsUtil dbsUtil, List<McOrgInfoBean> orgInfoList) throws Exception {
        List<String> delMchntNoList = new ArrayList<>();
        /* 查询营销活动原机构列表 */
        List<TMMcOrgInfo> newOrgInfoList = orgInfoList.stream().map(this::convertMcOrgInfo).collect(Collectors.toList());

        /* 获取上送机构列表、活动原机构列表 */
        McOrgInfoMapper mcOrgInfoMapper = new McOrgInfoMapperImpl();
        List<TMMcOrgInfo> oldOrgInfoList = mcOrgInfoMapper.selectMcOrgInfoList(globalInstId, globalMcNo);

        List<String> newOrgs = newOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        List<String> hisOrgs = oldOrgInfoList.stream().map(item -> item.getOrgId()).collect(Collectors.toList());
        rglog.info("机构变更-商户信息处理流程，本次上传机构列表size:<{}>,商户:<{}>", newOrgs.size(), newOrgs.toString());
        rglog.info("机构变更-商户信息处理流程，原活动机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        for (String orgId : newOrgs) {
            if (hisOrgs.contains(orgId)) {
                hisOrgs.remove(orgId);
            }
        }
        rglog.info("机构变更-商户信息处理流程，排查本次机构变更数据，待删除的机构列表size:<{}>,商户:<{}>", hisOrgs.size(), hisOrgs.toString());
        if (!hisOrgs.isEmpty()) {
            rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息");
            List<Object> mcMchntInfoList = getAllMcMchntListInfo();
            if (mcMchntInfoList != null && !mcMchntInfoList.isEmpty()) {
                List<McMchntInfoBean> mcMchntInfoBeanList = mcMchntInfoList.stream().map(this::convertMcMchntInfo).collect(Collectors.toList());
                List<String> mchntNoList = mcMchntInfoBeanList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                rglog.info("机构变更-商户信息处理流程，查询营销活动存量商户列表信息:<{}>", mchntNoList.toString());

                rglog.info("机构变更-商户信息处理流程，存在删除的机构列表，开始排查该机构下是否存在参加活动的商户");
                MchntInfoMapper mchntInfoMapper = new MchntInfoMapperImpl();
                List<TBMchntBaseInfo> mchntNoForOrgList = new ArrayList<>();
                for (String signInstId : hisOrgs) {
                    //查询该机构下所有的商户列表
                    List<TBMchntBaseInfo> mchntInfoList = mchntInfoMapper.selectMchntBaseInfoListBySignInstId(globalInstId, signInstId);
                    mchntNoForOrgList.addAll(mchntInfoList);
                }
                if (!mchntNoList.isEmpty() && !mchntNoForOrgList.isEmpty()) {
                    List<String> mchntNoListForDelOrgs = mchntNoForOrgList.stream().map(item -> item.getMchntNo()).collect(Collectors.toList());
                    for (String mchntNo : mchntNoList) {
                        if (mchntNoListForDelOrgs.contains(mchntNo)) {
                            delMchntNoList.add(mchntNo);
                        }
                    }
                    rglog.info("机构变更-商户信息处理流程，待删除机构列表下属商户列表size:<{}>,商户:<{}>", delMchntNoList.size(), delMchntNoList.toString());
                }
            }
        }
        if (!delMchntNoList.isEmpty()) {
            List<TMMcMchntInfo> delOrgsMchntInfoList = delMchntNoList.stream().map(this::convertMcMchntInfoForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表，size<{}>", globalInstId, globalMcNo, delOrgsMchntInfoList.size());
            deleteMcMchntInfoList(dbsUtil, delOrgsMchntInfoList);
            List<TMPlatBizTmp> delOrgsMcMchntList = delOrgsMchntInfoList.stream().map(this::convertMcMchntInfoToTmpForDel).collect(Collectors.toList());
            rglog.info("法人机构<{}>的营销活动<{}>删除商户列表临时表，size<{}>", globalInstId, globalMcNo, delOrgsMcMchntList.size());
            deleteMultiMcDetialInfoByBank(dbsUtil, delOrgsMcMchntList);
        }

    }

    /**
     * 获取营销活动商户信息列表(正式表)
     *
     * @return java.util.List<cc.rengu.igas.momp.common.entity.TMMcMchntInfo> 营销活动商户信息表
     * @throws Exception 异常信息
     * @author Jinan Liu
     * @date 2020/5/28 18:35
     */
    private List<Object> getAllMcMchntListInfo() throws Exception {
        List<Object> tmMcMchntInfoList = new ArrayList<>();
        PageInfo pageInfo = new PageInfo();
        int i = 0;
        pageInfo.setPageIndex(i);
        pageInfo.setPageSize(9999);
        TMMcMchntInfo tmMcMchntInfo = new TMMcMchntInfo();
        tmMcMchntInfo.setInstId(globalInstId);
        tmMcMchntInfo.setMcNo(globalMcNo);
        McMchntInfoMapper mcMchntInfoMapper = new McMchntInfoMapperImpl();
        PageResult tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
        if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
            tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
        }
        while (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult() && tmMcMchntInfoPageInfo.getResult().size() >= 1) {
            i++;
            pageInfo.setPageIndex(i);
            tmMcMchntInfoPageInfo = mcMchntInfoMapper.selectMcMchntInfoList(tmMcMchntInfo, pageInfo);
            if (null != tmMcMchntInfoPageInfo && null != tmMcMchntInfoPageInfo.getResult()) {
                tmMcMchntInfoList.addAll(tmMcMchntInfoPageInfo.getResult());
            }
        }
        return tmMcMchntInfoList;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param object 营销活动商户信息表
     * @return cc.rengu.igas.momp.facade.bean.McMchntInfoBean 营销活动商户信息对象
     * @author Jinan Liu
     * @date 2020/4/1 10:33
     */
    private McMchntInfoBean convertMcMchntInfo(Object object) {
        McMchntInfoBean mcMchntInfoBean = new McMchntInfoBean();
        TMMcMchntInfo mcMchntInfo = (TMMcMchntInfo) object;
        try {
            /* 商户范围类型 */
            mcMchntInfoBean.setMchntType(mcMchntInfo.getMchntType());
            /* 商户范围号 */
            mcMchntInfoBean.setMchntNo(mcMchntInfo.getMchntNo());
            /* 商户范围名称 */
            mcMchntInfoBean.setMchntName(mcMchntInfo.getMchntName());
            /* 新增商户标志 */
            mcMchntInfoBean.setNewMchntFlag(mcMchntInfo.getNewMchntFlag());
            /* 退出标志 */
            mcMchntInfoBean.setExitFlag(mcMchntInfo.getExitFlag());
            /* 操作类型 */
            if ((mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_REFUSE_FLAG) || mcMchntInfo.getNewMchntFlag().equals(CommonConstant.MCHNT_NEW_FLAG)) && mcMchntInfo.getExitFlag().equals(CommonConstant.MC_EXIT_FLAG)) {
                mcMchntInfoBean.setOprType(CommonConstant.BIZ_OPR_INSERT);
            } else {
                mcMchntInfoBean.setOprType(CommonConstant.EMPTY_STRING);
            }
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", e.getMessage());
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfoBean;
    }

    /**
     * 营销活动商户信息数据库实体类和接口实体类数据转换
     *
     * @param mchntNo 商户号
     * @return cc.rengu.igas.momp.common.entity.TMMcMchntInfo 营销活动商户信息表
     * @author liujinan
     * @since 2021/6/24 11:10
     */
    private TMMcMchntInfo convertMcMchntInfoForDel(String mchntNo) {
        TMMcMchntInfo mcMchntInfo = new TMMcMchntInfo();
        try {
            /* 法人机构号 */
            mcMchntInfo.setInstId(globalInstId);
            /* 营销活动编号 */
            mcMchntInfo.setMcNo(globalMcNo);
            /* 商户范围类型 */
            mcMchntInfo.setMchntType(CommonConstant.ZERO_COMMON_CONSTANT);
            /* 商户范围号 */
            mcMchntInfo.setMchntNo(mchntNo);
        } catch (Exception e) {
            rglog.error("转换营销活动商户信息异常,异常信息:<{}>", StringUtil.ExceptionToString(e));
            throw new BizException(RespCodeEnum.SYSTEM_ERROR.getRespCode(), RespCodeEnum.SYSTEM_ERROR.getRespDesc());
        }
        return mcMchntInfo;
    }

    private TMPlatBizTmp convertMcMchntInfoToTmpForDel(TMMcMchntInfo tmMcMchntInfo) {

        TMPlatBizTmp tmPlatBizTmp = new TMPlatBizTmp();

        try {
            /* 法人机构标识 */
            tmPlatBizTmp.setInstId(tmMcMchntInfo.getInstId());
            /* 营销活动编号 */
            tmPlatBizTmp.setMcNo(tmMcMchntInfo.getMcNo());
            /* 商户编号 */
            tmPlatBizTmp.setMchntNo(tmMcMchntInfo.getMchntNo());
            /* 操作表英文名 */
            tmPlatBizTmp.setOprTableEname(TableNameEnum.T_M_MC_MCHNT_INFO.getTableNameCode());

            return tmPlatBizTmp;
        } catch (Exception e) {
            rglog.error("公共业务数据不可为空!");
            throw new BizException(RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespCode(), RespCodeEnum.MSG_VALID_CHECK_ERROR.getRespDesc());
        }
    }
}
